This works just fine in a standalone single player game, meaning the capsule half height changes to 40, however when I switch to 2 players, it’s not replicating. What am I doing wrong?
I know there is a built-in crouch functionality that already has replication, but I’d like my character to have the ability to both crouch and slide and these require different capsule heights.
Hey @Rev0verDrive thank you so much for the quick reply! I’m a bit new to Unreal and I’m not sure I completely understand your reply. Would it be possible to explain the steps a bit more or provide a screenshot of what it would look like in a BP? Thanks!
CMC uses client-side prediction which in simplest terms is the client executes movement input locally. It passes the inputs and it’s results to the server. The server executes the inputs and then compares its results against the clients. IF they are close enough the server sends an acknowledgement (ACK). If the difference exceeds tolerance the server instead sends a correction. The client then updates its simulation to match the servers result…approximately. Everything in a multiplayer game is based on approximations.
When you change a CMC state, speed or any other variable you apply the change locally, then RPC the server to “attempt” to make the change. Your flow logic must maintain server authority. You do not tell the server what values to apply.
For instance if you want to apply sprinting you change the CMC Max Walk Speed on the client, then RPC the server to take the same steps. But you don’t pass a float telling it what speed to change to. It must determine the value itself through logic or hard coded value.
Notice the Conditional checks before applying a speed change on both the client and server. You aren’t Commanding the action to happen. You are attempting. Conditions must allow for the change to be applied.
Here’s a more advance Sprint setup. The base logic flow is the same, but the application is more dynamic. I’m setting a custom State variable that will apply the max walk speed change based on other states.
The Locomotion Mode enumerator is a Repnotify. RepNotify vars execute a bound function when their values are changed. I have this function call a custom function that walks through all my other character state variables to determine the movement speed to apply.
Here’s the tail end of that movement speed function.
Yes, this is all quite a bit over the top for most games sprinting action. But the point here is the client determines the speed via rules and conditions. The server in turn does the same and maintains authority. If its value is different it’ll force the client to change.
Hey @Rev0verDrive thank you for that detailed explanation of the CMC, however I’m still not sure what I did wrong in my setup, why my Set Capsule Half Height isn’t replicating. Did I miss a step?
Also when you set halfheight it shifts from bottom to center and top to center. This offsets the mesh, hence it falls through the floor.
To fix this you have to set Relative location of the MESH.
My capsules default HH is 90.0, so when I scale it down to 40 I have to apply a -50 to Z on the mesh.
Furthermore, there’s an issue with CMC Network smoothing and set Relative Location on the mesh.
When network smoothing is enabled (Linear, Exponential) it caches the relative location of the mesh. So setting a new value only gets used for the frame it’s set in. It snaps back to the cached/stored value after that.
Disabling Network Smoothing will bypass the snap back to default relative location issue.
The only other work around here is to Set Relative Location (Mesh) on Event Tick.
You’ll need a conditional check here to determine when to apply.
Hey @Rev0verDrive just wanted to say thank you for all the info! It was a bit confusing at first, but I’ve watched several tutorials today and learning particularly about multicasting and rep notify helped me make sense of everything. Thanks for the help and for pointing me in the right direction!