UMG casting to NPC charackter fails in Binding of a Variable

Hallo,
I’m trying to display a variable defined in a character blueprint(enemy character not player character) inside a UMG 3D widget placed as a component ontop of this character. To clarify my scenario: it should be like the typical health,or money or what ever value hovering on top of an enemy.
i have exposed the variable in the NPC class blueprint and tried to bind it to a textblock in the UMG Designer, but the cast to my NPC fails and the variable is not displayed at all. I believe that i’m doing something wrong at casting and wondering what i should connect to the object pin of the cast node, is “self” wrong? In the UMG tutorial they use player character at the object pin, but my variable isn’t inside the player character its in the NPC class blueprint itself.
If anybody knows how to display a variable of an enemy actor on top of it, it would be nice to know. In the new feature video they showcase UMG exactly with something like this at 1:38 to 1:40(the building time on top of a the RTS Building),thus i thing it must be easy:)

Ah yea easy mistake to make :slight_smile:

Inside of your Designer you use “Self” as object which you try to cast to NPC. But self in this widget is the widget itself which is… well a widget and not a npc :smiley:

You will need to create another variable in your widget with the type NPC, make it editable and also check the box “Expose on Spawn”. This will allow you to insert another pin when you create this widget which then should be “Self” inside of your NPC character.

Cheers

Thank you very much, sadly i don’t get it :frowning: i have created the variable of type npc inside of my widget and replaced self with this variable but its still the same result. Could you please give me more details? Where do i have to insert an other pin? I’m not sure what you mean with “when you create it” because the widget is a component of the NPC and i think that i’m not creating it else where, or do i? Please correct me if i’m doing something wrong.

Ah right my bad. Whenever I talk about widgets I forget that you can use the 3D once as component which will skip the “Create Widget” node. Sorry about that!

In this case you will just have to get your widget on “Event Begin Play” (be sure to not use the construction scrip as the actor does not exist yet there so the reference “Self” will be invalid) and set the NPC variable.

Thank you again very much. I’m very sorry for having to ask in what object(the NPC?) do i have to get the widget on “Event Begin Play” and how would it help me at the binding?

Well you somehow need to get that variable over to the widget. In order to cast to something else than yourself you need to get it first. Usually you do this via a hit result or on overlap but in this case it’s part of the components so you can on event begin play (inside of your NPC) provide this to the widget.

Come to think of it since it’s a component of the NPC you could try “Get Owner” inside of the widget itself… since the npc is the owner.

Sorry for replying so late i was busy during the week. Unfortunately i don’t get it to Work. I have tried casting to the owner but i get an error(please see screenshot) It would be nice if someone form epic could provide a way of displaying enemy stats in an umg widget component hovering about this actors instances head, since this is a very basic Game element.

The 3D widget is relatively new and certainly not finished… To be precise it’s still experimental which is a label to show that this is not a feature which should be used for production but an early hands on feature which most likely has bugs and may drastically change with a new version which can potentially break all old work you did with this feature.

“Get Owner” is used to get the owner of an actor component… well widgets aren’t one and even though 3D widgets are it’s as I said experimental which in this case is lacking this feature because the component (which is generated to use it as a component) is not exposed and usable.

So you will have to use my first suggestion as workaround. On even begin play of your NPC, get your widget and set a variable of the type NPC inside of your widget to “self”.

That was very quick:) thank you one again for your answer i have tried what you have suggested but still the cast is failing. Maybe i have done something wrong in my blueprint. it would be nice if you could check them.

Edit: i have have fond my error:) the “cast object” in the NPC must be “get user widget object” and not self, now it works. Thank you again very much for all your help!!!