Replicating mesh movement

Hi,

For my game i want to make a door that’s controllable (open and close). If the player points at the door and presses ‘e’, the door opens perfectly fine. However, this is a multiplayer game and all other players other than the host can’t control the door and don’t see the door moving when the host opens/closes the door.

The door its movement is controlled by an blueprint. I’ve tried multiple replication settings, but none of them seem to work. I tried:

  • Static mesh replicates
  • Static mesh replicate movement (in the blueprint itself)
  • Replicate movement (also in the blueprint)
  • Replicates (also in the blueprint)

How should i go about this?

Another question, when i’m playing my game, it is very laggy. Is this an effect of using the 480 port from steam, or could this be something else?

Thanks in advance

You need to tell the server to open the door, you want to look into RPCs. Take a look at the replication part of the ue4 documentation.

I had a similar problem with replication for my doors. Here is what I found doesn’t work:

Have the client character or player controller open the door on the client, then an RPC call on the Door blueprint to the server to open the door, and then Multicast the door open back to the other players. The reason this doesn’t work is that RPC calls only work on objects directly controlled by a player controller. So the RPC calls on my Door blueprint were doing nothing.

Here is what does work:

Have the client’s player controller open the door by making an RPC call to the player controller on the server, then have the player controller on the server open the door blueprint, then have the position of the door be replicated automatically back to all other players (have to set is replicated and replicate movement checkboxes on the Door blueprint).

If you need screenshots of any of this, let me know.

Thanks! Screenshots would be appreciated :). I’m going to look into it.

Okay, i figured out i had to set my replication on multicast. Now, if the host opens the door, it replicates to all other clients and they see that the door is open. But when a client opens the door, they see the door opening, but can’t walk through it. Other clients don’t see the door opening/closing at all. So i now have to find out how this can be replicated from the client to the server. All help is appreciated :slight_smile:

Ok, here are some screenshots. It wouldn’t let me post this as a comment. Too much content. My example is a bit complex (you don’t need to use an interface like I did), but hopefully you can just use the parts of this that work for you:

Here is the key press handler in the client side Character class. This would work in the Player Controller as well and is a better choice if you have multiple Character classes. I removed the code I use to find which actor to plug in just to keep the example simple. A simple box collision or line trace will work fine to get the Actor to send in.

121202-replicatedoor1.png

This is the server side event that the RPC call above calls. It is also in the Character class. It calls an interface, but you could just have it call your Door actor directly. The important part is that this happens on the server. If it only happens on the client, then you get the situation where you can’t walk through the door even though it appears open.

121203-replicatedoor2.png

This is the event that gets called inside the Door actor:

121204-replicatedoor3.png

This shows the settings that need to be set on the Door actor to get it to replicate:

Here is the Rep notify that you see in screenshot 3 above. This is what opens or closes the door state on each client:

121206-replicatedoor5.png

Here is the Open Door function that actually moves the door to the open position on the client. The Close Door function is almost identical with just a different rotation. I you want to animate the door opening, you would do it here. Mine just instantly opens.

Let me know if you have any questions. The main idea is to use an Run at Server RPC to get the key press even to the server, then have the server do all the work and replicate it back with a Rep Notify variable (not a multicast).

The last screenshot would not post. I guess the limit is 5 images per answer. So here it is:

121208-replicatedoor6.png

Screenshots 1 and 2 look good assuming they are both inside either the Character or Player Controller. Screenshot 4 looks good as well.

I think the issue is with the Rep Notify. Have you used rep notify variables before? If not, here is how they work. When you set the variable for replication instead of picking Replicated, pick RepNotify. When you do this it will automatically created a function for you called “OnRep_IsOpen”. This method will be called on the client side whenever IsOpen changes on the Server side. Put the code in your 3rd screenshot inside the OnRep_IsOpen function that was created for you (don’t try to create it yourself) and you should be all set to go!

Thanks! I still have a few question. Where should i make the On Rep Closed or Open function? I now have it in the blueprint of the door itself (i called it after the ‘set open or closed’, as shown in screenshot 3). It all works fine (well, in singleplayer it does, i haven’t tested it in multiplayer yet), but in the Open Door, it doesn’t want to rotate.

As you can see in the images, i wasn’t able to copy your screenshots 100% correctly. Will it still work (provided i can get the default scene root)?

Images:

Thanks, i have that done now. I made an error with my screenshot, so there’s another one added now (the third one). If i try to add the default root scene, it only shows up for other blueprints.

Here are the settings I have for the Door blueprint:

121225-replicatedoor7.png

121226-replicatedoor9.png

I remember it not working until I checked “Replicate Movement” and then set “Replicates” on every item in the chain: InteractiveDoor, DefaultSceneRoot, and Door (static mesh).

ok, I see the issue… Your Set Is Open needs to say “SET w/ Notify”. Is Open is still set to "Replicated’ and needs to be set to “RepNotify” otherwise it will not work.

Here is a screenshot of how to set the RepNotify:

121227-replicatedoor10.png