I’m trying to set a character position using
SetActorLocation but randomly, my character goes to the wrong spot.
Here my full character creation process:
- I load my level using
MyGameMode::PostLoginfunction, I call
Client_PostLogin(Client RPC) to check weither or not I need to spawn a MyCharacter.
- If yes, in the same previous
Client_PostLogin, I call
Server_SpawnAndPossessVIVECharacter(Server RPC) in which I spawn an possess a MyCharacter :
Here is my spawn code
// Spawn the default pawn. // For now I just don't care about the spawn position. MyCharacter* NewPawn = Cast<MyCharacter>(GetWorld()->SpawnActor( GameMode->DefaultPawnClass)); // Possess the new pawn Possess(NewPawn);
MyCharacter::BeginPlaywill automatically be called. There, I set manually the position using the following code:
// Function bellow
SetActorLocation(StartLocation, false, NULL,
for (TObjectIterator Itr; Itr; ++Itr)
APlayerStart* PlayerStart = *Itr;
return FVector(0, 0, 0);
The actual issue
I have two
APlayerStart in my level, but of course only one is called “ViveStart”’. Randomly, my newly spawn MyCharacter pick of the two. No matter which location I tell him to be. I’ve also noticed that when I manually disconnect and reconnect the client, my character can also be at (0, 0, 0).
What am I missing there ? Possible issues could be:
SetActorLocationis not working as I expect
APlayerStartare maybe not created yet when I’m using them. But since I use them in a
BeginPlayfunction they should already be in the world.
- I’m an idiot
Thanks for reading. Hope you will help me figure this out. I’m just starting to understand properly Unreal Engine network “magic”.