Why doesn't my interface work?

Since I’ve been away from Unreal for a while, I guess I forgot how interfaces work.

The situation I have is that I create a widget in the Player Controller blueprint

Then, I use a line trace to try to govern its visibility from the player character blueprint.

I’m trying to pass the Widget as an object reference with this interface

image

What am I doing wrong here?

1 Like
  • you’re passing null values into the message
  • the implementation does not do anything, it’s passing a null ref
  • using an interface here makes little sense, but it’s ok to do so, ofc

When you create a widget in the PC, store a reference:

image

When you want to communicate with that widget, get player controller → cast (or message using the interface) → set visibility


You could employ an Event Dispatcher. Whenever the player traces, the PC’s widget becomes visible. Is this how it’s supposed to work?

1 Like

I’ve updated it to be like so but it still doesn’t work

It keeps telling me the variable is null.

Which variable? BP First Person Player Controller? How did you set its value?


The player controller is always loaded, get player controller → cast → call widget visibility.

I created a variable in the Player Character BP and selected BPFirstPersonPlayerController as its type

That’s a null reference - creating a variable does not instantiate an object. The variable is not an object - it just describes where in memory the object is. If you create a string variable and forget to type text, what do you get - a null string so to speak. You must set a value.


Okay, well now it’s working, except the Set Visibility node where it collapses the widget when the line trace isn’t hitting anything is receiving a null variable even though it’s getting the same variable as the one that makes the widget visible

You’d need to cast here, too:

Avoid accessing data from non-executing branches.


@davi1521 You can still use an interface as you originally imagined:

  • the interface:

  • implementation in the PC:

  • tracing:


However, since framework classes - possessed character, player controller, game mode, etc are easily accessible from anywhere, and you do know upfront what you’re dealing with, using an Interface will just unnecessarily clutter things. You mileage will vary, ofc!

Good luck!

Alright, well I have yet another issue. I’ve moved on to another part of the logic and I’ve come across an interface event that just doesn’t seem to want to fire.

In the below, we have a Get component by Interface Node that targets the Actor being hit by the player’s line trace. It fires the Go to Dialogue Box interface event on this blueprint, however…

In the actual Dialogue Box blueprint (below), this event does not fire.

Oh Christ I’m dumb. A widget isn’t a component, that’s why it’s not picking it up