i have this widget and i’m trying to get the name variable from the enemy but the enemy isn’t the player but a character i spawn so what do i put at the object node?
side note : also i spawn the enemy multiple times
Hey @primaldragon100!
Well, you have to find a way to detect the specific enemy character, then pass that reference to the widget. This can be a pretty complicated process, and it can really depend on everything else you have going on.
If these names appear above the enemy I’d suggest the widget being a component OF the enemies and then they could just have that as part of the enemy blueprint.
Can you widen the scope a bit and let us know what it is you’re trying to do? Thanks!
so as you can see i’ve made it so when i click the attack button i get the list of targets to attack, the enemies in other words, as for the enemies since they spawn dynamically i’ve made this variable in the level blueprint in order to ‘feed’ them to the corresponding widget to make the buttons appear dynamically so with those things what should i put at the object node of the cast to enemy in order to get the correspoding enemy name variable and should i do something more than just putting something at the object node of the cast to enemy?
Awesome sounds like you’ve done nearly all of the work here!
It’s going to involve using that Array of enemies you have there, and utilizing the index to choose which one you want to use. Start at 0 then for every widget you spawn you increase the index of the next one by +1 until you reach the end and spawn no more.
Other than that… You don’t even really NEED the cast node because your “Select Opp” variable is already of the class “enemy”, so you should be able to just pull “Name” off of that without a cast.
Hi!
Here two easy ways to get your enemy name:
You can do it by getting the actor name or by using a string variable, let me explain:
First method (Owner Actor):
1- Create the widget with a text and bind the content of the text block:

With a bind function you can change your text block while the game is running.
2- create the possessor variable actor:
3- code the bind function to get the possessor display name and set the text block:
4- setup the widget in your blueprint:
In this case I’ve put the widget above the enemy’s head
For the size 500x500 (in screen mode) is a little too big for me, so I used 10x10.
5- Last but not least write this code to set the widget possessor variable in the begin play event:
6- result:
- You can use a string to set directly the name of the enemy instead of getting the display name:
-The bind function:
-The begin play event in your enemy actor:
-The result:
For what you’re actually doing you can set the Begin play of the Enemy (so when it spawns) event like this:
You get all the widget of the class [your widget] (so only that widget if you didn’t create any children and, if you did it, just add a branch that check the name or something else that say that you’re using the right widget) then you cast it to your widget and set the name variable.
Hope I was helpful, if you have questions I’ll be happy to answer it
so to elaborate the widget with the button is the child of a different one that spawns it like this, and i want the enemy name to appear in the text in the button of each such child with the bind
In the button widget you add a bind and a variable with expose on spawn enable so you can set it when you add the child.
First you need to set the SelectOpp variable as an actor not as an Enemy.
Second you need to add to your “add_enemies” function (when you create the button) a node that set the SelectOpp variable as the enemy that you are spawning
Right now I can’t take a picture to show you exactly how to do it because I can’t access my computer but if you’ll need more explanations give me some time.
but if i set select opp as an actor where am i gonna get the enemy variable name from?
and at the second point what type of node : enemy, actor, something else?
The enemy is to specific so it will work only with the enemy actor and not with other enemy actors.
Using the actor you can set that variable with all the actors you want (so all the enemies).
For the second point just get from the result output pin in the create button widget. With this output you can search for the node “set Select Opp” and set the variable with the enemy (the output index pin) that you get from the for each node.
but when i tried switching the type from enemy to actor it couldn’t connect to the variable name so how would i get name then?
use the display name node or create a variable called name in the widget and when you soawn the enemies (add_enemies function) set that variable too:
From the for each index output get the name variable of the enemy and then you set the name variable of the widget.
Like this:
(the add_enemies function)
Sorry for the low quality sketch
create a variable: type string and name “name”
and put it into the result node
do you mean to do this at the button widget?
and can you explain in more detail what to do here since this is clearly wrong
The button it’s correct, the function need some adjustments:
You’re ecposing the Select Opp variable on the create node so you don’t need to set it again.
ok but the set name will not connect its target node with the return value of the add child and is the select opp ok like this?
Yes it’s correct try it in the game