Character location is wrong using SetActorLocation

Hi everyone,

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 GetWorld()->ServerTravel(TEXT("/MAPNAME?listen?SpectatorOnly=1"));
  • In MyGameMode::PostLogin function, 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);
  • Obviously, my MyCharacter::BeginPlay will automatically be called. There, I set manually the position using the following code:

    if (GameInstance->IsServer())
    {
    // Function bellow
    FVector StartLocation(Server_GetVIVEStartLocation());
    SetActorLocation(StartLocation, false, NULL,
    ETeleportType::TeleportPhysics);
    }

    ///////////////////////////////////////////////////////////////////////////////
    FVector MyCharacter::Server_GetVIVEStartLocation()
    {
    for (TObjectIterator Itr; Itr; ++Itr)
    {
    APlayerStart* PlayerStart = *Itr;
    if (PlayerStart->GetName().Contains(“ViveStart”))
    {
    return PlayerStart->GetActorLocation();
    }
    }
    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:

  • SetActorLocation is not working as I expect
  • All APlayerStart are maybe not created yet when I’m using them. But since I use them in a BeginPlay function they should already be in the world.
  • I’m an idiot :smiley:

Thanks for reading. Hope you will help me figure this out. I’m just starting to understand properly Unreal Engine network “magic”.

Best regards.

EDIT: All right, so I figured out that SetActorLocation just doesn’t do anything and i’m trying to understand why. Here is how I configured my *MyCharacter * if it can help.

96501-sans+titre.png

Just for tracking purpose if someone gets into the same issue.

I’m actually using the HTC Vive for my project and the MyCharacter I’m talking about in this post is the representation of the vive. After looking deeper into my issue, I saw that my MyCharacter is in fact well placed in the world. The real issue is that the camera doesn’t follow properly my pawn, which is a totally different issue.

Best regards.