TActorIterator Error

Hello

Is there a way to iterate through all actors/blueprints in a scene or world?
I’m trying to build a plugin that will let me hide/show actors with a specific property, and after going through iterator materials I’ve found: RamasWiki, brettclutch’s question, IteratorDiscusion seemed pretty straightforward.

However I’m getting the following errors when I try to build from the source code:

Error	1	error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl GetObjectsOfClass(class UClass *,class TArray<class UObject *,class FDefaultAllocator> &,bool,enum EObjectFlags)" (__imp_?GetObjectsOfClass@@YAXPEAVUClass@@AEAV?$TArray@PEAVUObject@@VFDefaultAllocator@@@@_NW4EObjectFlags@@@Z) referenced in function "protected: __cdecl FActorIteratorBase::FActorIteratorBase(class UWorld *,class TSubclassOf<class AActor>)" (??0FActorIteratorBase@@IEAA@PEAVUWorld@@V?$TSubclassOf@VAActor@@@@@Z)	C:\UnrealEngine\Engine\Intermediate\ProjectFiles\Module.GaussArchButtonHideFurniturePlugin.cpp.obj	UE4

Error	2	error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl UObjectBaseUtility::IsA(class UClass const *)const " (__imp_?IsA@UObjectBaseUtility@@QEBA_NPEBVUClass@@@Z) referenced in function "public: void __cdecl TActorIteratorBase<class FActorFilter,struct FDefaultLevelFilter>::operator++(void)" (??E?$TActorIteratorBase@VFActorFilter@@UFDefaultLevelFilter@@@@QEAAXXZ)	C:\UnrealEngine\Engine\Intermediate\ProjectFiles\Module.GaussArchButtonHideFurniturePlugin.cpp.obj	UE4

Error	3	error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl UStruct::IsChildOf(class UStruct const *)const " (__imp_?IsChildOf@UStruct@@QEBA_NPEBV1@@Z) referenced in function "protected: __cdecl FActorIteratorBase::FActorIteratorBase(class UWorld *,class TSubclassOf<class AActor>)" (??0FActorIteratorBase@@IEAA@PEAVUWorld@@V?$TSubclassOf@VAActor@@@@@Z)	C:\UnrealEngine\Engine\Intermediate\ProjectFiles\Module.GaussArchButtonHideFurniturePlugin.cpp.obj	UE4

Error	4	error LNK1120: 3 unresolved externals	C:\UnrealEngine\Engine\Plugins\GaussArchButtonHideFurniturePlugin\Binaries\Win64\UE4Editor-GaussArchButtonHideFurniturePlugin.dll	UE4

This is the main class of the plugin I’m trying to build:

.h file:

#pragma once

#include "ModuleManager.h"
#include "Slate.h"
#include "LevelEditor.h"
#include "LevelEditorActions.h"
#include "SharedPointer.h"
#include "FGaussArchButtonHideFurniturePluginCommands.h"
#include "Internationalization.h"
#include "MultiBoxExtender.h"
#include "GaussArchButtonHideFurniturePluginPrivatePCH.h"
#include "UnrealEd.h"
#include "Engine.h"
#include "ActorEditorUtils.h"
#include "Editor.h"

#define LOCTEXT_NAMESPACE "GaussArchButtonHideFurniturePlugin"

DEFINE_LOG_CATEGORY(GaussArchButtonHideFurniturePlugin);

class GaussArchButtonHideFurniturePluginImpl : public IModuleInterface
{
public:
	/** IModuleInterface implementation */
	void StartupModule();
	void ShutdownModule();			

private:	
	void HideFurniture();
	void AddToolbarExtension(FToolBarBuilder &builder);

	TSharedPtr<FUICommandList> ButtonHideFurniturePluginCommands;
		// Stores a reference to the extension manager that we’ll be using to add our extenders. 
	// This reference is simply going to be used for clean up purposes, 
	// as we are required to remove all extensions upon shutting down the plugin / unloading it.
	TSharedPtr<FExtensibilityManager> MyExtensionManager;
	// Stores a reference to the created extension for the editor. 
	// Used for clean up purposes.
	TSharedPtr<const FExtensionBase> ToolbarExtension;
	// The object which stores all the extension information that we’ll be applying to the editor
	TSharedPtr<FExtender> ToolbarExtender;	
};

.cpp file:

#include "GaussArchButtonHideFurniturePluginPrivatePCH.h"
#include "GaussArchButtonHideFurniturePlugin.h"

void GaussArchButtonHideFurniturePluginImpl::StartupModule()
{
	UE_LOG(GaussArchButtonHideFurniturePlugin, Log, TEXT("GaussArch plugin for Button Hide Furniture Actors started!"));
	
	FGaussArchButtonHideFurniturePluginCommands::Register();
	ButtonHideFurniturePluginCommands = MakeShareable(new FUICommandList);
	ToolbarExtender = MakeShareable(new FExtender);

	// Set the button action
	ButtonHideFurniturePluginCommands->MapAction(FGaussArchButtonHideFurniturePluginCommands::Get().ButtonHideFurniture, FExecuteAction::CreateRaw(this, &GaussArchButtonHideFurniturePluginImpl::HideFurniture), FCanExecuteAction());
	// Set the button location
	ToolbarExtension = ToolbarExtender->AddToolBarExtension("File", EExtensionHook::Before, ButtonHideFurniturePluginCommands, FToolBarExtensionDelegate::CreateRaw(this, &GaussArchButtonHideFurniturePluginImpl::AddToolbarExtension));

	// Add the button to the editor
	FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
	LevelEditorModule.GetToolBarExtensibilityManager()->AddExtender(ToolbarExtender);


	MyExtensionManager = LevelEditorModule.GetToolBarExtensibilityManager();
}

// On button click event
void GaussArchButtonHideFurniturePluginImpl::HideFurniture()
{
	UE_LOG(GaussArchButtonHideFurniturePlugin, Log, TEXT("Button Hide Furniture is clicked!"));

	for (TActorIterator<AActor> ActorItr(FLevelEditorActionCallbacks::GetWorld()); ActorItr; ++ActorItr)
	{
		UE_LOG(GaussArchButtonHideFurniturePlugin, Log, TEXT("Found an actor!"));
	}
}

// Add the button to the toolbar
// AddToolbarExtension is a delegate of the FToolBarBuilder
void GaussArchButtonHideFurniturePluginImpl::AddToolbarExtension(FToolBarBuilder &builder)
{
#define LOCTEXT_NAMESPACE "LevelEditorToolBar" 
	UE_LOG(GaussArchButtonHideFurniturePlugin, Log, TEXT("Starting Button Hide Furniture Extension logic"));

	// Set the button icon in a variable
	FSlateIcon IconBrushHideFurniture = FSlateIcon(FEditorStyle::GetStyleSetName(), "LevelEditor.OpenLevelBlueprint", "LevelEditor.OpenLevelBlueprint.Small");

	// Set the button location
	// Method derived from the FToolBarBuilder class, passed via builder argument		
	builder.AddToolBarButton(FGaussArchButtonHideFurniturePluginCommands::Get().ButtonHideFurniture, NAME_None, LOCTEXT("ButtonHideFurniture_Override", "Hide Furniture"), LOCTEXT("ButtonHideFurniture_ToolTipOverride", "Set visibility of the Furniture Actors (F)"), IconBrushHideFurniture, NAME_None);
#undef LOCTEXT_NAMESPACE
}

void GaussArchButtonHideFurniturePluginImpl::ShutdownModule()
{
	// If a toolbar is extended, remove it after the module is removed
	if (MyExtensionManager.IsValid())
	{
		FGaussArchButtonHideFurniturePluginCommands::Unregister();
		ToolbarExtender->RemoveExtension(ToolbarExtension.ToSharedRef());
		MyExtensionManager->RemoveExtender(ToolbarExtender);
	}
	else
	{
		MyExtensionManager.Reset();
	}
}

IMPLEMENT_MODULE(GaussArchButtonHideFurniturePluginImpl, Module)

Commenting out or completely deleting the Iterator removes the errors, so I’m pretty sure that rest of the module is written somewhat properly. I’m also using FSelectedIterator in one other module, and it works as it should, so I’m not exactly sure what I’m doing wrong.

Here is the short version of the loop I’m currently stuck with:

for (TActorIterator<AActor> ActorItr(FLevelEditorActionCallbacks::GetWorld()); ActorItr; ++ActorItr)
     {
         UE_LOG(GaussArchButtonHideFurniturePlugin, Log, TEXT("Found an actor!"));
     }

#ObjectIterator

Do you experience any change in behavior using ObjectIterator?

 for (TObjectIterator<AActor> ActorItr; ActorItr; ++ActorItr)
      {
          UE_LOG(GaussArchButtonHideFurniturePlugin, Log, TEXT("Found an actor! %s"), *ActorItr->GetName());
      }

Notice I added to your log to give you more info

Thanks, I did try it earlier with pretty much the same effect. I modified it to the way you suggested, sadly I still got the same errors, minus the Error 3, posted in my OP.

Thanks for the tip for the display in the log, if I ever make it past the iteration.

Make sure to add "CoreUObject" to your Private- or PublicDependencyModuleNames in the *.Build.cs.