AI Not Moving To Player Location

Hello! I am having an issue with getting the AI to move after taking damage, I have an interface set up and the fire function from my player blueprint calls the interface and the AI does take damage, so I have a Branch, if the actors health is below 0 delete it, if its not play a hit sound and subtract damage from health. That part works fine, on the false part of the branch I added a sequence with an AI Move To node (my thought process is this 'if the AI takes damage then move to the players location), I breakpointed that node and the computer is reading it but the AI doesn’t move towards the player after taking damage. I am most likely doing something wrong but I can’t seem to figure out what could be going wrong. I got this to work in my AI controller, its on pawn sense and that works just fine, but for some reason it won’t trigger in this section of blueprint. If anyone has any ideas I would really appreciate it! Thank you!

Section of blueprint in question:

GIF of the issue in action:

Hey @TheSurgeon!

A few questions:

  • You mention you have AI movement that you set up already, that could be interfering/overriding what you currently have set up. Have you tried disabling your movement in your other blueprint (or section of the blueprint) to see if that is the case?

  • If you already have AI movement set up, why not trigger your move-to in your AI controller, whether in the controller or by sending/triggering a reference from this blueprint there?

Any additional information you can provide will be a big help in solving your problem!

Hi there,
Just for confirmation

  1. Did you add navmesh volume in your level covering the desired area?
  2. Is your enemy being spawned or is placed in the level? So check if it is set as controlled if spawned or placed in the world, inside blueprint class defaults.
  3. Are you saving the player reference before triggering AI move to ? I can’t see where that blue line came from.

Hey @Quetzalcodename !

Thank you for your reply! I disabled the AI move to in the AI controller blueprint and that didn’t have any effect, except for removing the ability for them to move.

In the AI controller I tried adding a Branch that says if the BasicEnemy health is < 100 to move to the player location, the only issue with this is that it only works if the AI has seen the player once, then lost sight, but it wont work if the enemy hasn’t seen the player at least once. I am not sure why its not initializing right away on begin play.

Heres a screenshot of the AI controller blueprint:

Thank you so much for your help! I appreciate it! :slightly_smiling_face:

Hey!

Yes there is a navmesh volume covering the level, the enemy is being placed (will be working on the spawn feature in the future), the player reference is a cast to player node and plugging the AsPlayerCharacter output and putting it into the Target Actor on the AI Move To node.

Is there a way I can reference the player blueprint without using a cast to? I use an interface function for the enemy and player to take damage both ways, can I do something similar so I don’t have to use cast to nodes all the time? I understand those can get performance heavy

Correct, you can add input and output pins to an interface event if you want to send or receive source and target references. In your case, you want to add an input variable type actor, because interfaces can be class independent. Make sure both player and enemies have implemented interfaces in their class settings pane.
If the player is causing damage to an enemy, add a “get a reference to self” and connect it to the input pin of the damage interface message (type actor). That way, the enemy will receive the damage value and the reference to the actor that is causing the damage.

Thank you! I added that actor variable input to the interface function, plugged that into the ai move to on take damage and added the player ref into the target and now it works just fine!

One more question, the AI loses sight of the player immediately, currently the AI will lose sight of the player sometimes and stop chasing only if the player hops past the AI quickly, otherwise the AI will chase the player around the map forever past obsticals that break line of sight, so I am at a bit of a loss for whats causing this. If you have any ideas on what could be causing that, it would really help!

All of the blueprint script is handled in the AI controller in the screenshot above, and here is a GIF of whats going on:

It doesn’t seem like this should be happening, I tried adding a bool marked to true whenever the AI sees the player and then looping it back into the move to command but that doesn’t seem to fix it.

AIController:

To prevent AI from losing sight, you can call Keep Focus from the AI controller and set the player as focus actor Conversely, call “clear focus” if a desired condition is met (distance, time, relative rotation). Now, if you are using pawn sensing component, check the sight cone angle settings.

I would recommend diving into behavior tree workflow not only because is flexible and modular, but also it contains several built in functions such as keep in cone, keep focus, move to. Also, custom nodes can be added using blueprints.

Ah thank you, I’ll look into the behavior tree workflow, does it also have a positive impact on performance/optimization?

1 Like

It’s modular and makes the creation of enemy classes more organized. And it is best for performance.

1 Like

Gotcha! Thanks a lot for the info!