Trouble Finding Pawns from GameMode

Hey guys, let me try to keep this short:

In GameMode::BeginPlay in doing the following:

TActorIterator<AContagionPawn> PawnIterator(GetWorld());

for (auto const Pawn = *PawnIterator; PawnIterator; ++PawnIterator)
{
    Pawns.Add(Pawn);
}

Where Pawns is an TArray of AContagionPawn.

No matter how I do it, it seems that PawnIterator only gets a single pawn when I actually have two in the scene. What is wrong?

(I’m also seeing an issue when I get two entries from the Iterator, but both of them point to the same pawn)


Now for the longer discussion, you may skip this…

  • I do have some suspicions - I’ve read that GameMode runs on the server, and I don’t really know if searching for actors in the game world from it is alright.
  • I moved this code around a bit - I’m just trying it on a custom GameState class, which is supposed to run both on server and clients, and now I get the duplicated items issue.

If the server spawns the pawns they should be there unless if they haven’t been spawned yet. Consider having the pawns register themselves on the GameMode when spawned instead of iterating them after the fact.

Normally the GameMode is the class handling spawning the pawns in the first place this could also be used to keep a reference to the spawned pawns.

Look for SpawnDefaultPawnFor or RestartPlayer.

Thanks a lot! This was the answer I was looking for. I will try this out in a few (right now I’ve moved the logic elsewhere).