So, I am interested, is there any “proper” way to interact with user interfaces from world?
For example, I have character and world-placed object (let’s say it’s an apple).
When player picks up that apple - apple added to inventory. When I want to use apple, it removed from inventory.
Now I do it with actor component.
Once apple picked up, actor component adds apple to inventory (user widget, let’s not talk about data saving for now). Then I send actor component to inventory widget and from inventory widget to inventory slot widget.
Once player pressed apple in inventory, inventory slot simply uses actor component sent earlier.
And once in actor component changes happened, with delegate I send back to character result of changes.
But for me, it looks like wrong way for communication between game events and user interface.
Is there any more correct and popular way to make (such or same) communication?
Basically, you want to treat your Apple as ‘data’, using a new UObject type (eg “InventoryItem”) instead.
This InventoryItem can have variables like: Static_Mesh, InventoryThumbnail, ItemName, ItemDescription, Weight, Cost, ItemType, etc.
If you need to see it in the world, create a custom Actor BP with a mesh component and a spawn-settable variable of object type “InventoryItem”. This new Actor class might be named something like “PickupActor”. When spawning the PickupActor, pass it the Apple InventoryItem. The PickupActor on construct uses this InventoryItem to initialize itself, setting the mesh, weight, physics if you need it, etc. This way you only have one (or a maybe a few subclassed) actor types that represent the pickup items in the world.
When you pick up the item, pass the Apple InventoryItem object to your inventory system, then destroy the PickupActor. The Apple InventoryItem object will still remain as long as there is a reference to it.
So, am I correct doing it by using delegates to return result back from user widget to actor component or sending component directly to user widget, and there is no way better and GameplayMessageSubsystem is an alternative?
I am clarifying because english is not native for me and I am making sure that everything had been understood correctly
sending component to widget is fine, the widget depends on the component
component binding to widget isn’t great, the component doesn’t care where an interaction comes from, just that it happens. ie the interaction could come from input, events etc not just the widget
GameplayMessageSubsystem or similar alternatives decouple everything so are great but can be overkill for small projects.