Got it. I needed to use SpawnActorDeferred instead of SpawnActor. Not really sure why. I think it’s because I construct the Actors elsewhere, before spawning, but idk where. Whatever…
Correct code:
void AEnShips::mySpawn(int x, int y, FVector pos, int size)
{
if (size == 1)
swarm[x][y] = ()->SpawnActorDeferred<ASmallEnemyShip>(ASmallEnemyShip::StaticClass(), FTransform(pos), nullptr, nullptr, ESpawnActorCollisionHandlingMethod::Undefined);
else if (size == 2)
swarm[x][y] = ()->SpawnActorDeferred<AMedEnemyShip>(AMedEnemyShip::StaticClass(), FTransform(pos), nullptr, nullptr, ESpawnActorCollisionHandlingMethod::Undefined);
else if (size == 3)
swarm[x][y] = ()->SpawnActorDeferred<ABigEnemyShip>(ABigEnemyShip::StaticClass(), FTransform(pos), nullptr, nullptr, ESpawnActorCollisionHandlingMethod::Undefined);
else
swarm[x][y] = ()->SpawnActorDeferred<AEnemyShip>(AEnemyShip::StaticClass(), FTransform(pos), nullptr, nullptr, ESpawnActorCollisionHandlingMethod::Undefined);
if (swarm[x][y]){
swarm[x][y]->x = x;
swarm[x][y]->y = y;
swarm[x][y]->SetActorLocation(pos);
}
}