Download

How to get owning actor reference?

I have a blueprint widget that has a progress bar in it and nothing else.
The rest of my project is in cpp. I have an actor (in cpp) in which I created a UWidgetComponent as a subobject, and I can see it above the actor once I spawn it.
The Actor also has a function GetProgressBarPercentage(), and I’m trying to find a way to access it from the blueprint widget. Since the widget is created in the actor, is there an easy way to cast it?

It seems to me that if you add a variable to your widget that stores an actor reference and then, when the actor creates the widget the actor can store a reference to itself in the widget. Then the widget will have a permanent record of the actor that created it.? That should work I think. Maybe there is a better way.
cheers
Podge

Hey gooddayyay**,**

I would add an actor variable to the widget and expose it on spawn, then you can use the reference to call the function.

Make sure you connect the actor reference when creating the widget.

(Picture is the progress bar binding in UMG)

thank you.

Does GetOwner() not work? You should be able to cast the result to your custom class…

[Edit] Reference: https://api.unrealengine.com/INT/API/Runtime/Engine/Components/UActorComponent/GetOwner/index.html