C++ objectIterator to Actor

Hello,

I managed to iterate over the actors in my game (thanks for his tutorials) by using this

for (TObjectIterator<AStaticMeshActor> act; act; ++act)
{ 
	FString actorName = act->GetName();
	if (actorName.Equals("Foobar"))
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Actor %s"), *actorName));
	}
	
}

My question is, how can I get the actor from the TObjectIterator?
I’d like to have AStaticMesh actor or AActor instead of the iterator.

Thanks for pointing me in the right direction
(and yes I’m not experienced in c++, sorry :wink: )

best

You already accessing it:

act->GetName()

TObjectIterator have “->” and * operators overrided, they return current item in iterator. You use “*” to point to object in iterator, like this:

SomeFunction(act*);

You don’t even need to cast, it returns in type you defined in template

Works great! thanks =)

Try to rebuild, also i not sure if this is related but by convetions used in UE4 all functions and varables names should start with uppercase letter, UHT read those to generate those files so it might be a cause.

hmm the code works but not the task I like to finish
could using a pointer be the reason for this problem?
(short sum up, I cannot attach the actor I’m iterating through)