Get Actors by variable

Have you thought about using tags?

Is there a way to check if an actor has a specific variable/property when iterating through them?
This is a sample of what I’m trying to achieve (currently I’m iterating through all of the actors):

    // Iterate through all of the actors 
    	for (FActorIterator It(InWorld); It; ++It)
    	{
    		AActor* Actor = *It;
            if (Actor->GetActorPropertiy("NameOfTheBoolVariable") == TRUE)
		    {
              // Do some stuff
		    }    	
        }

What I need is a way to find specific blueprints in the world and do something with them (Hide/Unhide them, later on modify some other properties etc). Basically extend the editors functionality to a specific group of actors based on their variable(s).

You can use reflection to access variables (though if they are declared in C++, they need to be labelled with the UPROPERTY stuff. You can read more about Unreals reflection here. The idea being you find the boolean value by iterating through the properties, cast it to a boolean property and then set the value.

for (TFieldIterator<UBoolProperty> PropIt(Actor->GetClass()); PropIt; ++PropIt)
{
    UBoolProperty* Property = *PropIt;
    if(Property->GetNameCPP() == "PROPERTYNAME")
    {
        if(Property->GetPropertyValue(Actor) == true)
        {
            // do stuff
        }
    }
}

I haven’t checked this code, but should work.

If it is a specific boolean variable, you might be better writing an interface with a getter method for getting it. That will be safer as you know that it will exist at compile time/avoids typos etc.

Thanks for both answers.

I decided to go with Antidamage’s answer as it makes my code look slightly cleaner.
After reading through this, here is what I’ve come up with:

void UUnrealEdEngine::edactHideFurniture(UWorld* InWorld)
{
	// Iterate through all of the actors 
	for (FActorIterator It(InWorld); It; ++It)
	{
		AActor* Actor = *It;
		// If actor is not already hidden and has the property and has furniture tag 
		if (!FActorEditorUtils::IsABuilderBrush(Actor) && !Actor->IsHiddenEd() && Actor->ActorHasTag("Furniture"))
		{
			// Save the actor to the transaction buffer to support undo/redo, but do
			// not call Modify, as we do not want to dirty the actor's package and
			// we're only editing temporary, transient values			
			SaveToTransactionBuffer(Actor, false);
			Actor->SetIsTemporarilyHiddenInEditor(true);

			// Show the list of actors that were found that match the criteria and were hidden
			UE_LOG(LogEditorActor, Log, TEXT("This actor is: %s"), *Actor->GetName());
		}
	}

	RedrawLevelEditingViewports();
}

I still have to work to see how to enable “Undo/Redo” and go through BSP models, but it does answer the question I’ve asked earlier. Thanks for both answers!