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.

Thanks for your answer !

How can I get “IsEmpty?” from the HitActor output ?

When I promote it to variable I can’t extract the “IsEmpty?” var from it. If just promote to variable, I can’t access anything specific because it doesn’t points to a precise class / actor. Maybe I should do a Line Trace For Objects instead ? That would cast only to a specific type of object and therefore access its variables with hit actor ?

Another problem is that there are multiple types of actors in which the players can hide, that’s why I used a class setup so I can have multiple objects with different meshes and small variations but still use the same code for all instead of making columns and columns of Cast To BP_XXX, Cast Failed, Cast to BP_XXX etc etc. Maybe there’s a better way to do that which could fit better with the help you’re giving me ?

Thank you for your answer, I’ll try that !

Cast the HitActor to the class where you defined IsEmpty?

Promote the result of the cast to a variable and it’ll be the right type.

Hi,

Small update here, for some reason it works only with the host player. When the host enters an object, the others players cannot enter until the host leaves it but when another player goes in if the object is empty, the host can go in as well. Here’s the code I did based on your explanation, maybe I didn’t understand well and if so I apologize in advance. This code has also been updated using the help provided by Chatouille.

As far as I know, “IsHiding?” (which is set to false by default) doesn’t seems to be the problem here. I’m guessing I missed something at Replication that doesn’t fires it from the other player.

Thanks in advance !

is this function defined in the microwave ?

if so, it won’t work properly from clients, move it into your character graph instead (add the microwave as an explicit parameter, so you can modify its value from there).

I’ve moved the code to the player instead of the microwave as it was before :

But I’m getting this error only from the client side, not the host :

What do you mean by “Explicit parameter” ? Is it something more than a variable as it is now ?

Don’t use HitActor there, your HitActor variable is set on client but not on server side. You need to pass HitActor as a parameter of the RPC event.

Click on your RPC_ServerUpdateObjectIsEmpty node (the red one), and add an input parameter of type BP_Microwave. Or alternatively, drag a wire from the Target pin of the SET node, back into the event node, it should offer you “Add Pin to Node” option.

Once the new pin is added, go back to where you call the event from client-side (after linetrace and when unhiding), and plug your HitActor variable to the new pin.

It all works now ! Thank you very much for you help and explanations ! :heart: