x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 :D

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

Best regards.

Product Version: UE 4.12
Tags:
more ▼

asked Jun 28 '16 at 04:37 PM in C++ Programming

avatar image

NymKappa
692 31 20 54

avatar image NymKappa Jun 29 '16 at 07:50 AM

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.

alt text

sans titre.png (28.3 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jun 29 '16 at 11:10 AM

avatar image

NymKappa
692 31 20 54

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question