Error with AI casting in 4.9.0

Greetings all, I’m attempting to program AI using a combination of blueprints, behavior trees and blackboards.

the youtube tutorial I’m mimicking is here (sadly, I think it is 4.5.): UE4 AI Tutorial: Shooting at the Player Part 1 - YouTube

The issue is when I try to cast to a controller in one of the tasks, the cast always fails. I want the AI not to only face the player character but who ever hurts him. I’ve tried several work arounds but each one does’t obtain the desired effect. If I could get the AI to do as in the video, I’d be happy.

Here’s an image of my blueprint.

Other than this issue, 4.9 has been the best. thanks.

Do you have a screenshot of the blueprint where you are actually setting the instigator? Take in mind that one thing is the Damage instigator and other is the Instigator of an actor (by the look of your screenshot it looks like you are getting the instigator of the bot itself, thats why im asking).

You should set the instigator in your blackboard data asset everytime a player or another actor hurts the bot.

Just Cast to your Player Character e.g Cast to ThirdPersonPlayerCharacter (Depending upon your character BP name), in object input add “Get Player Character” node. The output of casting to your character can be directly used as input in “New Focus”

Here is the screenshot of the damage system in the bot character blueprint in which I set the damage insigator to the instigating object. In the other screenshot I have the “random move to location” task where I set the blackboard key values. Hope this is what you where asking for. :slight_smile:

Iv’e tried that and it has worked. The only issue is that I want the bot enemy to attack who ever hurts him(even other AI.) not just the player.

Thanks though!

Maybe you could try setting the instigator during your take damage event. Something like this (add your anim montage call there, i forgot about it).

I just tried that and got better results, but the bot still isn’t setting the damage instigator as “focus.” In the “Event Any Damage” I cast to the controller. What is that you made your cast to?

I made a cast to the AI Controller. Maybe your problem is what its mentioned here

That seems similar, but the focus still doesn’t operate properly. However casting to the AI Controller causes the bot to face where the damage delivering shot came from. The Focus fails to work when I set the “New Focus” to a controller. I’ll attempt setting focus in the “Event Any Damage.”

Do you know of any other methods that would get the same result? Perhaps this isn’t the best way with the focus acting up.

I really appreciate the help!

Sorry I haven’t responded in some time. I’ll try to build something tomorrow morning and come back to you to see if we can figure this one out.

Thanks so much! I tried some different approaches last night and none of them worked.