guys im trying to call an interface that was implemented in a widget like this.

why isn’t this working? i thought the whole point of specifying a owner is so that we can call it later.
guys im trying to call an interface that was implemented in a widget like this.
You’re calling InitText
on the player controller. Does the player controller implement the DialogeInterface
interface? It looks to me as if the widget is the one that implements the interface, in which case the widget that you created in screenshot 1 needs to be the target for the InitText
node in screenshot 2.
well isnt the controller the owner of the widget? how else am I supposed to call it then there’s no other way to access widgets other than direct references maybe.
You already have a direct reference. You’re storing the dialogue widget in the Dialoge
variable in the first screenshot, so you can use that as the target for the interface call in the second screenshot.
You are right, the controller is the owner of the widget. But the owner has nothing to do with calling a function defined in an interface. An interface declares a set of functions and classes that implement that interface define those functions by implementing the specific functionality. When you make a call to an interface function in Blueprint, you need to pass as target an object whose class implements the given interface. How you store and get that object is entirely your own design choice.
that reference is in the game mode class. if I want to get access I probably need to cast to it which destroys the whole point of using interfaces in the first place.
If you want to avoid casting on the game mode, then you need to write an interface that your game mode implements, not one that the widget implements. If your situation is this:
DialogWidget
Then your setup should be closer to this:
DialogueWidgetProvider
with one function GetDialogueWidget
that returns a widget of type DialogWidget
GetDialgoueWidget
and passes in the game mode, no casting necessary.InitText
on the widgetYou’ll notice that there is no need to have an interface for InitText
anymore because you’re working with the dialogue widget class directly.