Hey guys, I want to discuss about widget best practice. Let me explain what I’m trying to achieve first.
I want to make a NPC interact system where when I interact to each NPC, they will show a widget that contain multiple option about what we can do with this NPC and each NPC have difference option amount and each of the option will behave different too. Example:
[NPC Trader]
-Option 1 > Buy (When click this button, another widget will open)
-Option 2 > Sell (Click this button n open another widget)
-Option 3 > Back (Just close the widget)
[NPC Blacksmith]
-Option 1 > Fix Weapon (Will fix the character weapon)
-Option 2 > Back
[NPC X]
-Option 1 > Action 1 (Do some action)
…
-Option 10 > Action 10 (Do some action)
So each NPC will have different option that can be done and player can interact to the option by clicking the button.

What is the best practice to do this? Should I create the widget for each NPC? Should I store all of the options in the NPC itself and generate the option later when interacting? But if I store all of the options within the NPC, how can I handle the button binding for each different action?
I appreciate any of your suggestions! Thank you very much!
i’d store data related to NPCs in a data table and when the widget is created, pass in data from that table.
in other words, the widget is setup to be a modular display that takes in a common template of data - its not related to a specific character
Thanks for your reply @BIGTIMEMASTER ,
but how do you handle the binding of those button since each button can do different action depends on the NPC?
you could have an event that is triggered by any input and then have it switch based on the current active character.
so say your characters are an enum or gameplay tags, you can switch on that.
So if at the widgets creation you say, “okay the input character is John”, then from the data table you can get an array of actions for john which you map to the buttons
You can think about it like you have a list of buttons and their order doesnt change. You have a list of characters and each has list of actions which should map to those buttons. It helps me a lot to draw out a diagram in figma or similar when planning something like this.
1 Like
I see, thanks for the explanation
I have an interface set up on the client. When “Interact” with the NPC, it will go “Oh player 0 is interacting with me. When I interreact I do this!” The interface can then get the player controller 0, and get the hud spawner reference (a hud actor that handles all the widget creation and destruction which can be called easily from pretty much anything that can get the reference from the controller), and trigger the event to create the specific widget. You can also pass the NPC reference to the event and the event can pass that to the widget. The widget can then access the “NPCWhoCalledUIRef” and pull the data it needs from the NPC.
You can then have an interface for each button. So the “Interact” button. The “HealNPC” button, the “HitNPC” button, the “GrabNPC” button etc.
1 Like