Multiplayer setup not updating the variables as intended.

Hi ! :grinning_face:

I’m working on a P2P multiplayer project and I encountered something that I’m unable to solve. I’ve been looking on the internet for an answer but couldn’t find a suitable solution to my problem (which may be somewhere, I hope).

In my game there’s a mechanic where players can hide into objects, players are not supposed to be able to enter an object who already contains another player. There’s in fact two issues that I can’t solve but I believe it all ties down to the same thing in the end.

I have one object class which contains all the code and then a child actor. First, when I enter the parent object on the server side it works but the other player can also enter the object.

Second, when I interact with the Child Actor, I can enter and leave but only once as the object will then always return a “False” value when I check for “IsEmpty?” when the raycast hits the object, note that this happens both on server side and client side.

First, the player makes an input to fire a raycast to check if the object is one inside you can hide :

Here are the two different events fired when their conditions are met :

It’s important to note that events which contains “RPC_SERVER_XXXX” are replicated with the option “Run on server” and the “RPC_PLAYER_XXXX” are replicated with the “Multicast” option.

And finally here’s what happens inside the object you can hide into :

Am I missing something about Replication ? Am I doing Replication the wrong way ? Is it something else ? :thinking:

If you need more infos about the setup, feel free to ask, I’m really stuck and will give you any info you may require to find a solution. You’ll find all the codes involved in my problem on this post.

Thanks in advance ! :smiley:

Your variable IsHding and IsEmpty should be replicated or rep_notify. RPC multicast to set local variable may cause problems like if an object is not loaded by a client at the time(players joining later or too far from object), the variable becomes not synced with server.
1.RPC_SERVER function call from players
2.Set rep_notify variable on server(do checking)
3.On rep_notify variable would teigger on all players. Notify UI to show variable changes.

You are also probably not checking/updating the correct object, “GetActorOfClass” will return any random matching object in the world, not specifically the one you are interacting with. Use HitActor from the line trace to check IsEmpty?, and store it in a variable, and when unhiding use the variable to update the object’s empty status.