For my personal research. I found it can be used by ActorIterator with for loop. like below.
for (TActorIterator<ATargetActor> It(GetWorld()); It; ++It)
{
ATargetActor* TActor = *It;
if (TActor == nullptr)
{
continue;
}
TActor->ChangeMaterial();
}
But I want to get a single actor not like for loop.
I know If I create an Actor named unque can be work like what I want. But I’m just want to know is there other way to do that SIMPLE.
If NOT, are using ActorIterator is the best way for now on Unreal Engine ?
Let’s say you want to interact with the object in front of the player. This is where a line/capsule trace would be perfect.
When the object spawns, it automatically registers itself in a list somewhere. The list could be anywhere, but most commonly you want to put them in some kind of a manager. Subsystems are very good starting points for manager objects.
Direct reference, e.g. you have a lever object in the game, and you directly reference the door object to it in the editor. The lever would have a UPROPERTY(EditAnywhere) AActor* Door property which will be visible in the editor so that you can set the reference yourself by hand.
You’ll find documentation on traces, subsystems etc. At the end of the day, this is just software design, so there is no definitive “this is how to do it” guide.