Hi all again,
I’m working off the official C++ TopDown Template:
I have my procedural map Actor AProceduralMap spawned at runtime from the GameMode like this:
void ATestProjectGameMode::BeginPlay()
{
Super::BeginPlay();
UWorld* const World = GetWorld();
if (World)
{
World->SpawnActor<AProceduralMap>(AProceduralMap::StaticClass());
}
}
The Actor AProceduralMap has a public FVector that is supposed to be the location where the player should spawn. And I would like to read this from the Character, to set its location accordingly.
Inside my ATestProjectCharacter I have added this:
void ATestProjectCharacter::OnConstruction(const FTransform & Transform)
{
FVector spawnLocation;
for (TActorIterator<AProceduralMap> map(GetWorld()); map; ++map)
{
spawnLocation = map->spawnPoint1;
}
this->SetActorLocation(spawnLocation);
}
(where spawnPoint1 is the public FVector from AProceduralMap)
It compiles, but doesn’t work.
I have noticed that, like this, no player get spawned at all. Usually it possess the BP Character placed manually in the game, or if it’s not present, it spawns one automatically using the BP and PlayerStart for the location (if that is not present either it places it randomly above the map), but like this nothing happens. What did I do wrong?