AI Patrol failing

I’ve set up a simple patrol script for an enemy AI character for my game, to make him idly walk around in some hallways. I currently have three target points set up at ground level, and I’ve included a screenshot of the script. It works perfectly in simulation mode, but when I actually play the game the AI Move To node constantly fails no matter what I do and what settings I use. He moves to the first point, and then stops permanently. Sometimes he only goes halfway and then stops. Yes I have a navmesh, yes the way is clear of obstacles, yes he is movable, yes I have a call to my PatrolToPoint event on BeginPlay.

Do you actually call that function again (patrol to point) off the “false” execution? Because after it becomes successful and increments the patrol point you don’t actually tell it to move to the next point by running this script again as far as I can see

Never mind…Didn’t see the end haha

Have you checked to make sure the array actually has 3 indexes?

It does, but I don’t think that would’ve been the issue anyway. It works perfectly fine in simulation mode, which tells me the player character might be interfering somehow.

So when you “simulate” and watch the blueprint execution it flows properly and continues to loop? But if you hit the play button and watch the AI patrol it goes to one point and stops? Is that what you are saying?

That is correct, yes. When I simulate the game the blueprint works properly and loops, but when I hit the play button the actor goes to the first point, and then the AI Move To node fails.

Odd, can you print strings for each of the possible outputs in your script? I want to see what exactly is happening during gameplay that is different from simulation. Is it failing because it can’t reach a point, is it failing because it believes it has reached the point or is it perpetually trying to get there but the mesh isn’t moving etc.

It prints a string when the Move To node fails, and each time that string is printed.

I just had it print a string for each action and outcome, and when it reached its point every one of them fired off once.

Can you do this for me…print these strings

  1. So off the top execution of AI MOVE TO drag out and say “moving”
  2. Off Success: Succeeded
  3. Off the True: Reached the End Of Array
  4. Off False: Set Next Point
  5. On Fail: I can’t go there
  6. Right After “Patrol to Point”: Patrol Called

So we can take a look at exactly what is firing and when because what you said was a bit confusing for me

When I played, “Moving” came up, and then when the actor reached the first point I got “Patrol Called” “Moving” “Set Next Point” “Succeeded” and then the actor stopped.

If I get too close to the actor it stops in its tracks, despite not being able to sense me.

So I am assuming those were written in reverse order (if you hit tilda during game play the little ~) you can see the order they actually executed. So basically it seems like the AI starts off moving to point 1, reaches point one, “succeeds”, goes through the false execution of the branch node, “sets a new point”, “patrol called” (should be prior to…“moving”) and then moves to it, but never physically “moves”. Does this execution keep going exactly like that? What I am thinking is that the first, second and 3rd point are all in the same spot. Try this… disconnect all print strings that we just made for now then “on event begin play” take the array of “patrol points” and connect it to a “for each loop” and have that print out the world location of each point and see what it says.

Do you have any other script that controls the AI movement? Is it set to block collision with the player or something?

I’m not so sure that’s the issue. I replaced the IncrementInt node with an int + int and set it up to add 1 to the Patrol Point Index, and now the actor patrols just fine if I never move. As soon as I move in the game, I get “I can’t go there” and the actor stops.

That’s super weird! Swapping an increment node for an integer+integer should affect anything haha, that is exactly the same thing. Well at least one thing is fixed! Is there any other script to control AI movement? Because I don’t know why that would be an issue if the player moves. Try adding a delay node for like 1 second and then off the “Failed” pin tell it to try and roam again. That might create an infinite loop depending on what the issue is or it might just jar the AI out of some loop it is stuck in and causing it to not move. (just throwing some ideas out at this point)

I have it scripted to move to the player and damage them if the PawnSensing component sees them.

Try disconnecting that and see if the AI will roam freely while you are moving.

I have before, disabling every script still causes the same issue. Your previous suggestion of having it start again on fail started an infinite loop of “Patrol Called” “Moving” “I can’t go there”

Hmm…figured, I dunno what to tell you at this point. I’ll let you know if I think up anything else, or if you find something else out let me know, but this behavior is really weird–bug maybe?