I’m making an inventory system for multiplayer.So,when on dedicated server, client1 pick something up,this item won’t dissapear,or when client 1 drop an item,client 2 can’t see this item on ground.
You have to make sure of two things when working via a server client model in Unreal.
-
Make sure in the class settings (or defaults… I always get those confused…) “Replication” and “load on net something” as well as everything else you need is enabled. That will make sure things on the server will be properly replicated to all clients.
-
Make sure you drop those items, etc serverside. You can display different things to different clients. You can also just drop things for one client on show specific items just to one which is what I assume you are doing. The easiest way to make sure you call something on the server is to create a new custom event for that functionality and select “Run on server” in the details of it.
Well if you still use “OnClicked” which is a PlayerController Event (aka executed client side) it won’t work.
You have to unplug it from your “Spawn Actor” and just call “OnServer” which will send the event to the server and execute it there.
Blueprint is linear. Only what happens from the execution line onwards matters. If you have a different event which will execute the same code on the server it will just be ignored because… well that’s not what’s called.
But I really need “OnClicked” what can i do?
Is there other ways?
You have to unplug it from your “Spawn Actor” and just call “OnServer” which will send the event to the server and execute it there.
If you call a “Run on Server” event it will be replicated to the server and executed there.
You just call the “OnServer” custom event you created from your “OnClicked”
Not all client events will be replicated to the server. That would be ridiculous. You will have to do that.
You should watch some tutorials on this whole matter or read the docs.
Thank you for your help!