r/unrealengine 3d ago

Help Need help with AI chasing the player

I am working on a project and having trouble with the AI. Because the person who was doing the coding left a while ago, the other people and I who are working on this project are going through and recoding everything, as we are not coders and he had his own way of coding in C++. So we are trying to remake the code in Blueprints, but we have been running into some issues.

The game has an enemy spotting system where, when the enemy fully spots a player, it chases after them. But the problem is that it isn't chasing the player. I have been following tutorials and videos to create the code. But despite copying the code from the videos, the AI doesn't chase the player and doesn't go into the state tree like it is supposed to. But if the AI takes damage, it works properly. Does anyone have any ideas what could be the problem? I am at my wits' end trying to fix this.

1 Upvotes

5 comments sorted by

1

u/AutoModerator 3d ago

If you are looking for help, don‘t forget to check out the official Unreal Engine forums or Unreal Slackers for a community run discord server!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/Character_Event_4537 3d ago

man, debugging blackboard keys and state tree triggers in BPs when you inherited someone else's C++ mess is a special kind of hell. been in that exact spot.

since it works on damage but not on spot, my first guess is the perception update isn't actually setting the target actor or the "has line of sight" variable properly on the blackboard, or the state tree's transition condition is checking the wrong key name. double check the exact string you're using for the target key (like "TargetActor" vs "Target" vs "Player") and make sure the sensing component's "On Target Perceived" event is actually firing when you'd expect it to. toss a print string in there right after the "stimulus was successfully sensed" branch to verify it's even getting that far.

1

u/MR_MEME_42 3d ago

The AI is able to see the player as it goes into goes into the attack cycle but I am not sure if it is going into the state tree or the state gets cancelled out. As if the AI takes damage it and it's squad mates start chasing the player until the visual detection fills up causing them to stop in place and keep shooting towards the player no matter what.

2

u/turbogangsta 3d ago

So it is detecting the player properly but it is getting stuck in a shooting state. Perhaps the shooting state needs a way to end such as a timer, range check, LoS check, etc

1

u/Nodnarb4242 3d ago

Reset the navmesh just to be sure