Ok. Let me try to put it together:
Your PlayerController has:
- An InventoryCore (some kind of array which saves Items)
- An InventoryWidget (the visual structure of an inventory)
- so he has an object Inventory and a reference to the InventoryWidget
Your InventoryItem has:
- an ItemDataStruct (contains all item information in a container)
You have visible Items (PickUps) in the world, when you pick them up, i assume
you destroy/despawn the PickUp and converts them into an InventoryItem and this will be added to your InventoryCore right?
Your InventoryCore can:
- Add Items
- Drop Items
Your InventoryWidget represents the Data inside your InventoryCore.
Workflow: (how i would do it from out of my brain)
PlayerController:
- Create your InventoryWidget and save its reference.
- This widget should get a reference to the players Inventory but how?
- inside PlayerController call a function (f.e. SetInventoryReference) with a reference of your current inventory as a parameter), this means there needs to be a function within your widget called SetInventoryReference and it expects an Inventory reference. So no need to “Get” the reference inside the widget´s logic it receives it from its owner (the player controller).
- your PickUp Event is called, and the parameter is the iteminformation which will be added to your Inventory
- after it is added your Widget needs to be updated, another functioncall from PlayerController (f.e. UpdateWidgetContent) fires a custom Event inside the Widget (UpdateWidgetContent) the param is the current Inventory reference and it replaces the reference within the widget.
to be continued…