Sepecific Variables out of generic Actor refrence

Hey guys!

I work on a Tower defense game in which the “Box Overlap Actors” node of the Towers gives them the array of enemys around them. The Output Actors are generic “Actor object Reference” from which i can not find specific Variables from my BP_Enemys (obviously). Is there a Way to Work around that? For Example i need the Health Variable, so the tower can For each loop every Actor reference to find the one with the most HP and set them as current target.

Thank you for taking the time to help me :slight_smile:

1 Like

You need use the node “cast to” → BP_Enemys

1 Like

Or return data with an interface.

Thank you for the quick reply!

I use the “Box overlap actor” node after an Event tick, because sometime enemys spawn inside the Collsion. On Overlap wont work in that Case.

I tried is with Interfaces, but if i set an Output Variable, i cant call the Interface as an Event in my Enemy BP, just as a function, but maybe i do something wrong here

  • when an interface has no return, it’s an event
  • but events cannot return data :frowning:
  • when interface returns data, it will be implemented as a function

i need the Health Variable, so the tower can For each loop every Actor reference to find the one with the most HP and set them as current target.

Untested but probably close to:

Make sure the return is valid before you ask the tower to shoot at that.

just as a function

What is wrong with that? It’s a good thing.

I use the “Box overlap actor” node after an Event tick

Consider using a slower firing timer. 10 per second may work equally well but will be 6 times faster.


You can use casting for this, ofc. You’d rely on inheritance heavily in a tower defence game.

Seems a bit green to get into those interface messes, don’t scare away the new ones :joy:

1 Like

Insanely detailed help, thank you for that!

Excuse my dumbness, but how do i “call” the “Get Stats” interface in my BP_Enemy, if it only appear as a function in that Blueprint? Since it always appear with an incoming execution pin, i have to attach that to an event, right?

Not sure I understand what you mean. Once the enemy implements an interface (very bottom):

image

You’ll get the chance to implement the functionality, double click to implement:

But in this case you call the Event “Talk” and not the “Get stats” or are they connected somehow?

1 Like

But it’s hard to disagree with @DomusLudus. In this particular scenario, it seems casting would more convenient:

The tower would call:

To find the target.

2 Likes

An blueprint interface can have as many functions as you need. I updated the image to avoid confusion.

Give me a Sec to try this out, i kinda remember that the cast always failed

1 Like

For casts to work well, you need inheritance which is, arguably, more complex. And you can still combine it with interfaces, ofc for the ultimate mind****. :innocent:


If you use inheritance, you can cast to base class.

2 Likes

Oh wow, in case of the Interface solution, i somehow had in mind that after calling the “Get Stats” message in the Tower BP, you also have to make an Event inside the Enemy itself to set the Variable Health to the current HP of the Enemy. But the function itself sets the value (After you hook the Health Variable from the enemy to the Outputnode of the function, like you have shown in the picture), without having an extra event.

The cast to node might also be a good solution, thank you for that, too!

1 Like

Yeah, once you wrap you mind around blueprint comms and inheritance, things really do open up.

Good luck!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.