Behavior tree AI waypoint

Can anyone tell my why this is only working some of the time? I set up an array system to have my enemies randomly walk between points that I set up.

When I hit play the first time it almost never works, but after the second or third time the enemy seems to be moving to the appropriate point.

It is randomly getting a number that it can’t use?

It seems ‘legit’. As it’s happening sometimes use ‘print string’ node for debugging. But print your random integer value instead of ‘hello’. Analyze it and see which waypoints causing trouble.
In viewport you can press P to see green navmesh area. If your waypoint is out of that area,it’s not accessible. Also check Z axis of your points. If points are above/below ground it can cause trouble.

There is a flaw with your code. For example, lets say there are 4 waypoints. Your Random Int in Range will return an int between 0 and 4 (5 possible numbers), but the array only contains 4 indexes (0-3, 4 numbers). To fix this just subtract 1 from the length. Then hook up the difference to the Max input. I hope I explained this well enough

Thanks! Made perfect sense and fixed my problem!

A key point that people starting out with blueprint seem to forget is that arrays ALWAYS start at 0, so you have to adjust for this by either subtracting one or adding in a blank array variable placement holder. Its quite common in programming.

Or just use Last Index instead of Length, since the Length node gives you the number of entries in an array while Last Index gives you the last index in the array.