Download

Replicate Freeze / Rotation

So I’m trying to do something which I thought would be fairly simple, but I guess when it comes to networking and replication, things aren’t quite that simple. I have a simple third person character setup that handles movement and such. What I want is when the player is holding down a button, the player will freeze its rotations. This is done by enabling and disabling the Use Rotation Controller Yaw. The character’s movement is replicated, but I’m not quite sure how to replicate this action. The only way I have replicated something is by using RepNotify, which I don’t quite see how that would work, and function replication is not quite working either. If anyone could help, that’ll be great!

If i understand this correctly, you want, at the press of a button, make the player unable to rotate?

In your playerController, add a boolean “RotationEnabled” with default value true. Make it replicated.
In the events InputAxisMouseX and AddInputAxisMouseY, before doing anything else, check if “RotationEnabled” is true. only if its true do the inpuit calculations, if false, do nothing.

For InputActionFreeze :
Right now you’re setting these variables on the client, but they also need to be set on the server:
Add custom Event named “SERVER_Freeze”, set it to run on server and with a boolean input variable.
In this “SERVER_Freeze” e vent you set your “RotationEnabled” variable to the input boolean variable
In your InputActionFreeze -> Pressed you call “SERVER_Freeze” and set the input boolean to true.
In your InputActionFreeze -> Released you call “SERVER_Freeze” and set the input boolean to false.

What now happens is that when you do any InputActionFreeze, your client will send a message to the server “hey, i want to freeze my rotation”. The server sets the values accordingly.
This change will then be replicated and whether you can rotate is determined by the replicated “RotationEnabled” variable which is used in your mouseX and mouseY events.

Basic rule for multiplayer is : If you want the clients to change anything gameplay-related, you should make a RPC call to the server (custom event which is set to “run on server”, the server then does the gameplay-changing calculations and sets replicated variables accordingly and/or does RPC calls to clients/multicasts.

I also like to add the prefix SERVER_ , CLIENT_ or MULTICAST_ to those events so i can easily see which events are meant to run on the server, the client or all clients)

The problem is that you are only setting “UseControllerRotationYaw” client-side on the controlled character so the server is never made aware of the change. (Input events only occur client-side)

Add a RunOnServer event and set “UseControllerRotationYaw” server-side too.

The CharacterMovementComponent takes care of the rotation replication from there.

Thanks you guys, this really helped me out. I guess I was overthinking that function replication wouldn’t be the answer; forgot how simple it was. Anyways, we got it to work! I ended up having to set Use Controller Rotation Yaw client side as well. Thanks!