Cast to Unknown Enemy Actor

I am making an AI with Dynamic Targets.
The Default Enemy is the player pawn.

But if some other Actor hits this Actor, (stray bullets, friendly fire) it will attack the Damage Causer instead.

It all works fine until the DamageCauser(which is the new Enemy) dies. Then he just keeps hitting at the dead body because the AI Actor doesnt know that his Enemy is dead.
Until someone else damages him and he gets a new Enemy…

My Question is how can my AI cast to this Enemy Actor to see if he is already dead.
Since the Enemy is not my pawn, but rather a changing Target i just don`t know how to cast to it…

Engine’s generic AActor class doesn’t have any concept of “death”, or even “health” for that matter. In general when Actor gets destroyed all “unreal” references to it, like the ones you make in BP, get cleared automatically, so either just check if it’s None, or implement your own class of pawn or character, introduce concept of Health, cast to your custom class and check if Health < 0 :wink:

Thanks for answering MieszkoZ, but thats not quite my problem.
My AI Actors all got their Health Variables and a Healthsystem responding to damage.

My Problem is that my Enemy Actor can always change and i dont know where to cast to.

I’m afraid I have no clue what you’re talking about. What do you want to achieve? Give me an example.

You can:

A) Cast to the parent class, if it actually has the variables you need. It is never a bad idea to have a parent class such as GenericEnemy and then have different child blueprints for all your other enemies. That way, you only define default variable and functions once.

B) Use an interface. Create a blueprint interface with a function such as “Get Current Health”, then include it on each of your Enemy class blueprints and give it it’s own method to obtain health per class. Then just call it using “call using interface” with the actor reference.

Thats a good idea with the Parent Class storing information everybody shares…
I am going to try that.

I have three different AI classes, and i never knew where to cast because each one could have been the DamageCauser.

Thank you both for your time, sry i couldnt be clearer about my problem…