Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

AI Actor Script

Product Version: UE 4.14
patroltopoint1.jpg (320.8 kB)
more ▼

asked Mar 28 '18 at 01:29 AM in Blueprint Scripting

avatar image

23 3 5 9

avatar image Nebula Games Inc Mar 28 '18 at 02:01 AM

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

avatar image Nebula Games Inc Mar 28 '18 at 02:02 AM

Never mind...Didn't see the end haha

avatar image Nebula Games Inc Mar 28 '18 at 02:04 AM

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

avatar image Aethryx Mar 28 '18 at 02:09 AM

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.

avatar image Nebula Games Inc Mar 28 '18 at 02:12 AM

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?

avatar image Aethryx Mar 28 '18 at 02:14 AM

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.

avatar image Nebula Games Inc Mar 28 '18 at 02:22 AM

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.

avatar image Aethryx Mar 28 '18 at 02:30 AM

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.

avatar image Nebula Games Inc Mar 28 '18 at 02:35 AM

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

avatar image Aethryx Mar 28 '18 at 02:42 AM

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.

avatar image Aethryx Mar 28 '18 at 02:46 AM

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

avatar image Nebula Games Inc Mar 28 '18 at 02:48 AM

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.

avatar image Aethryx Mar 28 '18 at 02:53 AM

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.

avatar image Nebula Games Inc Mar 28 '18 at 02:50 AM

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

avatar image Aethryx Mar 28 '18 at 02:59 AM

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

avatar image Nebula Games Inc Mar 28 '18 at 02:58 AM

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)

avatar image Nebula Games Inc Mar 28 '18 at 03:01 AM

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

avatar image Aethryx Mar 28 '18 at 03:05 AM

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"

avatar image Nebula Games Inc Mar 28 '18 at 03:09 AM

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?

avatar image Aethryx Mar 28 '18 at 03:13 AM

I moved the start point to a different part of the map on the same floor level as the actor, and now everything works fine.

avatar image Nebula Games Inc Mar 28 '18 at 03:15 AM

Nice! Silly issues sometimes haha Glad it's working.

avatar image Aethryx Mar 30 '18 at 04:37 AM

I neglected to mention that my game is set up to stream multiple sub-levels in order to save resources. The area that this actor is meant to patrol in is a streamed level, and now starting from the beginning the AI Move To fails again when its level is loaded.

avatar image Nebula Games Inc Mar 30 '18 at 11:47 AM

Well that's the problem right there! You can't tell the AI to patrol to a point that doesn't exist yet. If it isn't streamed it's not there so you're always gonna get an error. All the points have to be in one level.

avatar image Aethryx Mar 30 '18 at 07:36 PM

I moved the target points to the persistent level, and now the AI moves but frequently gets stuck in random areas for a while, then continues moving.

avatar image Nebula Games Inc Mar 30 '18 at 10:24 PM

Well at least it is continuously moving now, AI does occasionally get "stuck" you would have to check those specific areas of your map and see what might be holding the AI up. Look at the blueprint during simulation and see where the path finding logic might be breaking down a bit and code a work around for the AI so if it can't reach a point after 2 or 3 seconds select a new point etc.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question