Hi,
Yeah, it was a “Widget Component” I added to the actor… I have just tried calling a method on it from the actor, in a similar fashion to your examples, but I’m running into so many problems now its unreal (excuse the pun)…
I have a “widget” called “Health” which is the little bar that should show above the NPC. I have added a Widget Component to the actor and set the Widget to by “Health”. When I then try to call a method within that I’m getting issues because Health isn’t of the same type and doesn’t inherit from Widget Component… Gah… I was hoping this was going to be like a 5 minutes to add feature…
I have tried the “GetOwner”, but that isn’t available within a Widget. There’s not a “GetOwningActor” either. All I can get is a “GetParent” but that assumes it will be another Widget…
Update…
I have managed to call the custom event within the widget finally… in the blueprint for the actor, where I’d added the WidgetComponent, I dragged that into the graph and from that use the “Get User Widget Object” which gave me my “Health” widget… from that I could then call my custom event within it.
So, I think I’m in a place where, I can update it now… albeit it not how I would have liked, and the design is now different from how I’ve done the player hud… but if it works it’ll do for now…
Update 2…
Yeah, this is an utter mess…
Because my actual Health component is being added in the construction script, the first call to the OnHealthChanged event is missed by the widget, because it isn’t being setup to receive those messages until BeginPlay. I figured I’d move those nodes to the Construction Script… I can’t do that either…
I can’t “Create” the widget, because you can’t do that in the Construction Script apparently, only from BeginPlay etc… I can add a “WidgetComponent” within the construction script, but then not set the user widget I want it to use, for some reason nothing appears within the “Assets” display/search.
So I’m left with a really messy situation here… I cannot believe this is so difficult, and can see why now in that article I saw they just dumped a variable in the widget and then set it from the actor to get the reference to the actor.
Update 3…
I have something working now, its not exactly as I would like it, but it is working. I have taken what you suggested about having the widget just updating the display, and used that approach, so the logic/code is in the actor blueprint, and it just fires through a value to the widget. I had to change a few things around with my use of the construction script and add the health component manually in the blueprint, but now those changes are made, the event is responded to correctly when its fired.
Thanks for the suggestions and taking the time to reply @Everynone, appreciated