Avatar

Game Developer

Lazy Perfectionist

TActorIterator & TActorRange

If you want to collect class-specific actors that spawned in the world you can use TActorIterator.

for (TActorIterator<ACharacter> Iter(GetWorld()); Iter; ++Iter)
{
    ACharacter* Character = *Iter;
    //If IsValid
    Character->Func();
}

There is also a version of the Ranged For feature available in C++11.

It’s called TActorRange. With this, we can iterate it safer and easier.

for (ACharacter* Character : TActorRange<ACharacter>(GetWorld()))
{
    //If IsValid
    Character->Func();
}