Trouble replicating "Orient Rotation to Movement"

Newbie question here.

I’ve made a simple action for a ThirdPersonCharacter that toggles the “Orient Rotation to Movement” property. However, I’m having trouble with the replication of this property for clients.

For the “Start Sprint” and “Stop Sprint” events, I’ve tried all 4 replication options with no success:

  • Not Replicated:

  • Successfully toggle on the owning client, but is not replicated to other clients.

  • **Multicast: **

  • Successfully toggle on the owning client, but is not replicated to other clients.

  • **Run on Server: **

  • Fails to toggle on the owning client, but is successfully replicated to other clients.

  • Run on Owning Client:

  • Successfully toggle on the owning client, but is not replicated to other clients.

From my understanding, shouldn’t the “Run on Server” option also replicate to the owning client? Am I missing something obvious here?

Alrighty. No run on server will just run on server :wink:

Usually with a variable you’d set it to be replicated and then use the run on server to update the variable. The changed value will then replicate to all the clients. Im not near a computer to see whether that variable is replicated already or if its possible to change it in blueprints.

if you cant set that variable to replicated there is another trick that probably wont make sense the 1st time you read it but stick with it :wink:

Create an int variable, set it to replication notify. This means that when the variable value is changed and replicates it runs a function on the clients. The value of the int is irrelevant you’re just using it so when its value changes it runs that notify function on clients.

Create the rep notify function and in the function set the new value of your ‘orient to movement’.

Now this is where it will seem a bit strange if it doesnt already but these are the crazy things you have to do with UE4 replication :slight_smile:

So to get everything to replicate you’ll want to create an event for ‘run on server’…in the event you’ll update that int variable, just increment it(not the orient to movement variable), now…
very very important…after you’ve updated the int variable in your event you’ll want to run the rep notify in that same event aswell. This is because rep notifys dont run on the server so you’re telling the server to manually run that function.

The rep notifys on clients will run automatically.

Now the orient to movement variable should be the same across all clients and the server.

So to summarise…int variable set to rep notify, run on server to update int which will fire off rep notify on clients, manually run rep notify in event so server runs that rep notify function aswell.

Its worth knowing this method cause its used everywhere in multiplayer i.e. shooting a gun, playing animations.

One gotcha worth knowing, a variable wont replicate on the clients if the value on the client is already what you’re trying to set it to. The rep notify will not run either on the clients but it will on the server as you’re manually calling it. So this is why you use that int variable to run the replication as everytime you update it you’re incrementing the value so it should never be the same and you wont run into that problem.

Hope that made sense :slight_smile:

I’ve managed to solve this problem. Many thanks @savagebeasty for pointing me in the right direction.

There’s one thing I need to correct you on though:

  • When the RepNotify variable is changed in a custom event that is set to “Run on Server”, the onRep function is called **BOTH **on the server and on all clients. So, the additional onRep call is not necessary.

Here’s my final solution for reference:

…and in the *onRep *function:

Thanks again for your help. :slight_smile:

Ah apologies for the onrep notify I only do it in C++ and you have to call it manually there. Glad you got working good stuff :slight_smile: