I can construct a inventory widget within the player character’s blueprint and add an ‘‘item slot widget’’ with the Add to wrap box command, but I can’t have an NPC go to the actor and contact it to add it to the player’s inventory. System wants the Inventory Widget to be constructed within the NPC’s blueprint. But when I do that, it’s no longer the player’s inventory, it’s the NPC’s inventory.
I’m sure there’s a simple solution, but I couldn’t find it. Thanks in advance.
The easiest way to achieve this is by using the Actor. Since the Actor already has a reference to the Widget, the NPC can communicate with the Actor, and then the Actor can update the Widget.
If you are using C++, you can use delegates. Here’s a brief overview:
The NPC can add a delegate.
The Widget can bind to this delegate.
When the delegate is called, the Widget can perform the necessary actions.
Another approach is to handle the communication through the Game Mode. However, be cautious about placing too much logic inside your Game Mode, as it can become overly complex.
First of all, thanks for your reply. I’m using the Blueprints and I researched the delegate command you mentioned. As far as I understand, this is done with Event Dispatchers in Blueprints.
I tried following a new path with Event Dispatchers and it worked. Since I am a newbie, I do not know much about the this features, but i think it is enough to create a custom event, at least in such simple operations.
I created a ‘‘Event Dispatcher with a custom event’’ at the beginning of the code series that creates the ‘‘item slot widget’’ in the player character’s Blueprint and added it after the ‘‘AI Move To’’ node in the NPC’s Blueprint. It works properly as if the player character is picking up the item.