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"

Pawn movement not replicated to client

I have a simple test project.

I start the multiplayer game with two pawns (not characters) for two players to control. Each one has their own window in PIE (listen server)

The client reads an input button and sends a movement vector to the server through an RPC.

The server moves the pawn correctly. With the two windows in PIE I can see the pawn moving in the server version (listen server), but in the client the pawn doesn't move.

The Pawn BP has Replicates, Net Load on client, Replicate Movement, and Always Relevant Checked.

Any ideas what I'm missing?

The RPC:

 UFUNCTION( Server, WithValidation, Unreliable )
 void Client_SendMovementToServer(FVector ReqMovement);

 void ATestPawn::Client_SendMovementToServer_Implementation(FVector ReqMovement)
 {
     MovementComp->AddInputVector(ReqMovement);
 }

MovementComp is a simple UMovementComponent. If I call AddActorLocalOffset directly, I get the same result.

If I add another RPC from the server to the clients, then I get the expected results, but why do I have to? I thought the "Replicates" checkbox handled that automatically in the background. If not, why is that checkbox there to begin with? The client that's in the same window as the server in PIE gets replicated correctly. The remote client on its own window is the only one not being replicated.

Product Version: UE 4.9
Tags:
more ▼

asked May 16 '16 at 10:17 AM in C++ Programming

avatar image

rantrod
1.5k 47 47 215

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Movement component has it's own replication that takes care of network lag and client side prediction. You don't have to do RPC. Just call AddInputVector on client.

more ▼

answered May 16 '16 at 11:47 AM

avatar image

mpo
573 23 15 46

avatar image rantrod May 16 '16 at 05:26 PM

As far as I can see, replication only happens from server to cluent, so if I make a call to AddInputVector on the client, there will be no movement; Which is what I saw when I tried it. I believe CharacterMovementComponent does handle the message from client to server, but not the UMovementComponent which is what I'm using.

avatar image mpo May 16 '16 at 05:47 PM

My mistake. It refers to CharacterMovementComponent not PawnMovementComponent. My advice should work if you reparent to ACharacter and use AddMovementInput() method.

avatar image rantrod May 16 '16 at 09:27 PM

I still want to know why my pawn movement is not replicated to the client. Sure, I could fix this one specific case, but in the future if I move a pawn in the server, and don't see the movement replicated to the client(s), I'd like to know why.

I was assuming I didn't have to manually do the parameter replication stuff for position, but do I?

 void ATestPawn::GetLifetimeReplicatedProps( TArray< FLifetimeProperty > & OutLifetimeProps ) const
 {
     DOREPLIFETIME( RootComponent->RelativeLocation );
 }

???

avatar image mpo May 17 '16 at 02:05 PM

If you take a look on engine sources, UMovementComponent class does not support replication. This means that even if you call SetIsReplicated(true) on server, nothing will be replicated. https://docs.unrealengine.com/latest/INT/Gameplay/Networking/Actors/Components/

If it goes to actor replciation, you have to call SetReplicates() and SetReplicateMovement(). Then it should be replicated with his location, rotation and all replicated properties.

If your actor has replication turned on, you change location and cannot see this change on clients - you probably change this location on client not on server.

btw. Relative location is component location in actor local space. Moreover You'll have to override GetLifetimeReplicatedProps in your RootComponent, not actor that owns it.

Maybe it's time to share this test project ?

avatar image rantrod May 17 '16 at 06:50 PM

Like I said, I tried it with ReplicateMovement and without it, with a movement component and without it and every combination thereof.

On the Pawn tick I have: if (Role == ROLE_Authority) which I think restricts it to the server. I also see the movement happen perfectly on the listen server, so I know it's working. Just never propagated to the client.

I see nothing in Epic's documentation about an Actor's location and rotation propagated through the network if 'Replicates' and 'ReplicateMovement' are on.

Do I have to do GetLifetimeReplicatedProps for having the location propagated? Also not in the docs, but I haven't tried it.

I'll simplify the project to just this example and post it later.

avatar image mpo May 17 '16 at 09:10 PM

I see nothing in Epic's documentation about an Actor's location and rotation propagated through the network if 'Replicates' and 'ReplicateMovement' are on.

link text

Do I have to do GetLifetimeReplicatedProps for having the location propagated? Also not in the docs, but I haven't tried it.

GetLifetimeReplicatedProps can be used to replicate your custom class member variables. See: link text Location and Rotation that we're interested in are replicated by ReplicatedMovement property filled in AActor::PreReplication function.

I guess that there are additional conditions that are blocking your example project from correct behavior. Project packed up will be helpful.

avatar image rantrod May 17 '16 at 09:52 PM

Ok I do see the line: "bReplicateMovement : Set to true if you want to be able to move the Actor and have its position be updated on clients automatically. Pawns have this on by default."

Which is obviously not true according to my test case. I posted it as a bug as well, but I'll look at posting a simple sample project to show it doesn't work on the simplest case.

avatar image mpo May 17 '16 at 10:41 PM

Bug in engine is a very brave hipothesis... https://www.dropbox.com/s/tfakp23hi9t7a5r/2016-05-18%2000h36_59.mp4?dl=0

 AMyActor::AMyActor()
     :Super()
 {
     PrimaryActorTick.bCanEverTick = true;
     TestTime = 1.0f;
     SetReplicateMovement(true);
     SetReplicates(true);
     bAlwaysRelevant = true;
 }

avatar image rantrod May 18 '16 at 08:07 AM

Brave, yet I think it was a bug in UE4 (though I appreciate the video and help).

So I commented everything out that wasn't just the simple move-the-actor-in-the-server-tick. Ran it, and it worked. I thought, "great, now I can add everything back in one-by-one until it breaks and I'll see what was wrong".

I added everything one-by-one, testing after each addition. I ended up adding everything back in, and it still working. Same.Exact.Code. My conclusion is that it was a BS UE4 actor corruption crap like it's happened to me so many times in the past. Such a buggy piece of crap codebase.

avatar image mpo May 18 '16 at 09:04 AM

Sometimes removing Game/Intermediate directory helps. All glue code generated by UHT is stored there. after this you have to regenerate project files and reopen Visual Studio.

avatar image Krzysiek_TATE Apr 05 '17 at 12:38 PM

Hmmm... I know it's been a while, but I had same problem, and the solution was actualy pretty easy. I forgot to call Super::GetLifetimeReplicatedProps( OutLifetimeProps ) on the beginning of GetLifetimeReplicatedProps func. I assume that you could have thesame, since you didn't call it on your code example. I'm just saying if someone else did thesame mistake ;)

(comments are locked)
10|2000 characters needed characters left
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