# AI Patrol failing

**URL:** <https://forums.unrealengine.com/t/ai-patrol-failing/421072>\
**Category:** AI\
**Tags:** ai-navigation, target-point, unreal-engine, Blueprint, question\
**Created:** [March 28, 2018, 1:29am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072 "2018-03-28T01:29:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aethryx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aethryx](https://forums.unrealengine.com/u/Aethryx)\
**Post date:** [March 28, 2018, 1:29am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/1 "2018-03-28T01:29:35Z")

</div>

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.

 ![235337-patroltopoint1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/5/c/05c0d49ed6ffb0ebffef32e59dcb914d2895bc2c.jpeg)

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 2:01am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/2 "2018-03-28T02:01:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 2:02am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/3 "2018-03-28T02:02:06Z")

</div>

Never mind…Didn’t see the end haha

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 2:04am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/4 "2018-03-28T02:04:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aethryx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aethryx](https://forums.unrealengine.com/u/Aethryx)\
**Post date:** [March 28, 2018, 2:09am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/5 "2018-03-28T02:09:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 2:12am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/6 "2018-03-28T02:12:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Aethryx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aethryx](https://forums.unrealengine.com/u/Aethryx)\
**Post date:** [March 28, 2018, 2:14am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/7 "2018-03-28T02:14:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 2:22am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/8 "2018-03-28T02:22:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aethryx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aethryx](https://forums.unrealengine.com/u/Aethryx)\
**Post date:** [March 28, 2018, 2:30am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/9 "2018-03-28T02:30:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 2:35am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/10 "2018-03-28T02:35:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aethryx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aethryx](https://forums.unrealengine.com/u/Aethryx)\
**Post date:** [March 28, 2018, 2:42am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/11 "2018-03-28T02:42:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aethryx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aethryx](https://forums.unrealengine.com/u/Aethryx)\
**Post date:** [March 28, 2018, 2:46am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/12 "2018-03-28T02:46:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 2:48am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/13 "2018-03-28T02:48:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 2:50am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/14 "2018-03-28T02:50:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aethryx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aethryx](https://forums.unrealengine.com/u/Aethryx)\
**Post date:** [March 28, 2018, 2:53am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/15 "2018-03-28T02:53:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 2:58am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/16 "2018-03-28T02:58:48Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Aethryx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aethryx](https://forums.unrealengine.com/u/Aethryx)\
**Post date:** [March 28, 2018, 2:59am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/17 "2018-03-28T02:59:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 3:01am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/18 "2018-03-28T03:01:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aethryx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aethryx](https://forums.unrealengine.com/u/Aethryx)\
**Post date:** [March 28, 2018, 3:05am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/19 "2018-03-28T03:05:28Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [March 28, 2018, 3:09am UTC](https://forums.unrealengine.com/t/ai-patrol-failing/421072/20 "2018-03-28T03:09:00Z")

</div>

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?

[Next page](https://forums.unrealengine.com/t/ai-patrol-failing/421072.md?page=2)
