How to send interface messages to individual NPCs from UI Widgets without hardcoding references?


Hi everyone,

I’m working on a dialogue system using Blueprints in Unreal Engine, and I have a question about communication between a UI Widget and NPC actors via a Blueprint Interface.

Here’s the situation:

  • I have a Widget Blueprint that contains buttons.
  • When a button is clicked, I want to send a notification to an NPC using a Blueprint Interface function (e.g., StartDialogue).
  • I’m avoiding using Get All Actors of Class or Cast To for performance reasons.
  • I understand that I need to set a reference to the target NPC in the widget, but I’m not sure what the best way is.

Currently, if I manually assign a specific NPC reference to the widget (like by name), then all duplicated widgets will send the message to the same NPC, which is not what I want.

What I want is:

When a widget is created for a specific NPC, it should only communicate with that one instance of the NPC.

:red_question_mark: My question is:

What should I set as the target reference in the Widget so that each widget talks to only one, specific NPC instance—without using Get All Actors or hardcoded names?

Any best practices or clean solutions for this kind of setup?

Thanks in advance!

1 Like

You do need a reference, but the point with blueprint interfaces, is that can be an actor reference.

If there’s a widget for each NPC, why not get the NPCs to create their own widget?

1 Like

As @ClockworkOcean said, you need at minimum an actor reference. You can get that by simply line trace pinging them when you interact. Use hit actor from the result.

2 Likes

Thank you very much!

In my setup, the content displayed in the Widget differs depending on the NPC. So, I used a Blueprint Interface (BPI) to send that Widget information from the Widget to the character.

At that point, the character’s BPI already had a reference to the NPC’s actor, so I promoted that reference to a variable in the character blueprint.

Then, I sent that actor reference variable from the character back to the Widget, and used that reference within the Widget to send notifications to the correct NPC.

Looking back, I wonder if that process was inefficient.

1 Like

interfaces are more about reusability than efficiency, so if you plan to reuse the widget on different classes then its a good idea

1 Like

That’s true, avoiding hard references is another goal.

1 Like