Execute Crouch Function on Server?

Hi again, I went about creating a crouch system with replication. However, I’ve stumbled upon a roadblock.

The problem arises when actually in-game. The Server crouches when ‘Crouch’ is pressed, but when the Client presses ‘Crouch’, nothing happens! :frowning:

My Crouch Function may not have been set up correctly as it is rather basic. I am not entirely sure how to set it up properly, and I need help in that regard.

I intend to have the remote clients replicate to the server if crouched is pressed and have the crouch function executed on the server, which in return, replicates it back to the client and the client then executes it.

If Remote: Remote Client presses ‘Crouch’ >> Replicates to server >> Server executes the crouch function >> Server replicates crouch function back to client/s.
If Authority: Executes the crouch function for self.

Side Question: I’ve seen many people take this approach for replicating player actions in a Multiplayer environment, but is this really necessary and are there better solutions? I need animation states to be replicated correctly later on and have actions (e.g. Crouch, Jump, etc.) to sync up properly too.

I plan to implement my own crouch function with smooth crouching by setting the capsule half height as well as set relative location for the cameras and use my own boolean later on. The problem is that the function (crouch in this case) only executes on the server and for the server, not the owning client.

How do I get it to run on client and server?

the replication for crouching is built into the C++ Character and CharacterMovement classes, so you don’t need to worry about replication to use it in blueprints.

This should replicate correctly for both clients and servers:

24539-crouchreplicated.jpg

if you want to make your own replicated crouching function from scratch, you should not use Character::Crouch(), because it expects to be called from the local character you are playing as, not just the server version of that character. the reason your code didn’t work for the client was because you kept calling Crouch only from the server, and its not designed to be called that way.

here is an example of why checking authority too early might break replication code:

This doesn’t work for me at all. Running 4.7.2 most movement seem to replicate fine except for crouch. I can see jumping is replicated fine.

I have this same question. Only on my end, I have it setup to run on server when crouch is pressed, then multicast to clients. However when setup this way, I get the opposite crouch function. For instance, when the server character crouches, the client sees them standing up, and when the server un-crouches, the client sees them crouching. same goes for the client, the server sees the opposite of if the client is crouching.

This is probably not the correct way to do this, but I got it to work by implementing it as so:
When couch input is pressed activate a server event, which then activates a multicast event, which then runs the code based on a branch, if it is not crouched. Multicast then runs a branch based on if it is crouched. Both the server event and multicast event run the same code for crouching, except that the multicast event goes into a separate branch with the opposite effect. It’s probably running twice, but I couldn’t find another way to replicate the crouch so it could be properly seen by both client and server.

Hey Check out this YouTube video [link text][1] this might solve the issue of what you are facing.

[1]:

Crouch and UnCrouch are replicated already. You don’t need to do any RPC, just call them on the owning client and do what you need to do (i.e. adjust the mesh location) when the OnStartCrouch and OnEndCrouch events are triggered.