Place the Character at a specified location

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?

OnConstruction function is called way before the actor is placed in the world therefore you don’t see the effect, I would suggest you to move the set location to BeginPlay which is the last step of the spawning process or passing the the spawn location when you call the the spawn function.

Hi lion032, thanks for the answer. I just tried replacing OnConstruction with BeginPlay but the player never spawns.

Who is spawning the ATestProjectCharacter?

I think it’s the GameMode? The official TopDown C++ Template has a ACharacter C++ class, and from that, a BluePrint, with the mannequin rig in it. The GameMode is configured to use the BP as the Default Pawn Class. But I still haven’t understand if subsequent changes to the ACharacter C++ class will be reflect on existing BPs, or not.

I would try another approach,
Create a BP game mode class, on begin play spawn a player start actor where you want to spawn the player, and override the FindPlayerStart event to return the player start actor you just spawned.

How do I make the overrided FindPlayerStart return the custom PlayerStart? (the whole BP concept is still quite confusing to me…)