I searched and found this wiki post that I followed but can’t get it work. I suspect the wiki is out of date or has invalid code samples to begin with as I don’t understand the c++ code sample.
Basically the goal is to iterate through all the player starts in the game and pick a random one. I don’t understand this for loop construct or how this magical “ActorItr” comes from and neither does my compiler.
What am I missing? → I’ll attempt to add to wiki once solves. Thanks Guys.
AScepterCamera::AScepterCamera(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
for (FActorIterator ActorItr<APlayerStart>(()); ActorItr; ++ActorItr)
{
this->SetActorLocationAndRotation(ActorItr->GetActorLocation(), ActorItr->GetActorRotation(), false);
}
}
For some reaon 's method seems to be outdated and FActorIterator make error like the template on it does not exist in it anymore… instead i found TActorIterator which seem to work
//in h in class
TArray<APlayerStart*> SomeArray;
//in cpp
for (TActorIterator<APlayerStart> ActorItr(()); ActorItr; ++ActorItr)
{
SomeArray.push(*ActorItr);
}
Push all PlayerStart pointers to array as i showed and then randomly pick one of them from array ;]
And as said, you should not use that in constructor not only world pointer in () is most likely initiated which will cause the crash, but also your PlayerStart won’t exist at that point in game memory. Do it in BeginPlay() or PostInit()