So, I have an Inventory system that works as expected and I have modified that system to work with containers. Everything works as expected except one thing. I cannot seem to figure out how to replicated an event so that the inventory updates every time someone takes an item out. I have it setup right now so that players can open it, see random items that are generated, take items out and if they close their “Container Inventory Widgets” and re-open them, they’ll see that the items are gone. I know it has to do something with either Event Dispatchers or On RepNotify event in the replication section. Only thing is, I have my inventory system in an Actor Component and all of my functionality for it, in there. So I don’t know how to update widgets for the container from an actor component. (I assume you can’t but don’t know what else to do, short from rebuilding my inventory system)
Any Help is much appreciated! Thanks!
Also, I followed a tutorial for parts of this system so linking other tutorials isn’t really helpful. Just if someone that knows replication could point me in the right direction, that would be suffice!
Could really use some help please
Calling the Event Dispatcher inside the On_Rep function should do the trick. Note that the OnRep_ functions only gets called on the host/server if you call the Set w/Notify node otherwise it only gets called on the clients.
The widget should bind to the Event Dispatcher and update itself.
I tried this, I still can’t get it to work properly. I am going to redo my inventory widget and inventory component a bit differently. The way I have been doing it is giving me more problems than it’s worth. I know that way you are talking will work if I do things a bit differently. Thanks for the advice!
Heres what my blueprint looks like inside the “Inventory Component” which is just an Actor Component that is added to everything that has an inventory. (NPCs, Containers and players)
Alright, so after digging around and compiling about 1000 times. I finally figured it out. It’s so simple it hurts.
Basically when the player clicks the button(Take All) in the “Container Widget” it sends a server RPC to the Inventory Component for the Player character.
While the Server RPC Sequence executes, it calls the “Client Transfer Items” RPC that Executes on All and every client does that sequence. Heres a few screenshots to clarify what I am saying.
Here the player sends the Server RPC by clicking on the “Take All” Button.(This event is on the “Container Widget”) The rest of the events are on the “Inventory Component”
Here the Inventory Component executes the Server RPC and calls the Client RPC as well as telling all the Clients to refresh inventories
Here is the Multicast refresh event that gets all actors of class and checks to see if they are in the same container, if true then refresh inventory.
Here is the actual refresh event that is called per client