I am trying to create a chest inventory system. Currently I am having trouble initializing chests with their own inventory.
The chests have item actor arrays which are instance editable. The chest on the left is supposed to have the LionAxe and the chest on the right is supposed to have nothing. When I start the game however, they seem to share the exact same inventory, the items even move the same on the grid.
I believe the problem is that I use the GetActorOfClass node in the inventory blueprint to get the inventory component when I am initializing the grid. I don’t think this gets the particular owner of that component, but instead gets all chests, therefore it treats all chest inventories the same. I think if I could get the actor owner reference for this instead, it would work. I can’t figure out a way to get that though; I get error messages with every other node I try. Does anyone have a method to do this.
Yes, it’s definitely reference related. “Get Actor of class” is going to return the one closest to world 0 most of the time. You’re activating chest 2 but getting chest 1 inventory, most likely.
Instead of “On Initialize” doing everything, I’d suggest making a custom event on the widget blueprint you have there, and casting to that widget to activate the custom event from the chest object or player, after the widget has been created. That custom event should have an array input node, so you can pass the inventory array through from the chest to the widget.
You are right that you should create a new widget every time a chest is opened then remove it from parent when it’s closed.
I don’t know what your “Close chest” widget code looks like but you certainly need to use “Remove from parent”, so then when you initialize a new chest inventory widget you have less chance of using the old one by accident.
I really hope this helps you out, feel free to ask more questions!