I'm lost here

So, I’m trying to make a custom behavior on my class blueprint so that it will look to one of 8 patrol points in the level, rotate towards it and then eventually it will go to it’s location, but it’s not working at all. Sometimes it even gives me an error that it couldn’t find the “Patrol Point” reference to make the rotation… I’m really lost here, any ideas? (tell me if I didn’t explain enough :3)

Hi. I think you have to check an ArrayLength node. It gives the number of items inside array, not the maximal accessible index.

Hey,

I’ve just made my system work the way I wanted, so I thought I’d share the logic behind it in case someone gets a similar problem. :3

I’m not used to commenting on my code, so I’ll explain the thought process writing on this thread. Before someone comments: “You could just use NavMeshes and Behavior Trees for AI movement!!!” Yes, I could… but I still don’t work well with those systems and for now these types of exercises are really good for my learning purposes, so yeah, I’ll stick to making my own AI through blueprints for now lol. (If anyone’s an expert on behavior trees and wants to teach me some of it or link me to good documentation on those, I’d love it!)

First off, that’s my setup and I wanted the pink cube to patrol around these 8 random locations on my map.

The first thing I did was make a system to make the cube find a random patrol point to be it’s target. I’ll go into more detail on how I did that when I get into the function itself, but for now, the casting was a failsafe method of making sure that I was making my target the location of the EXACT patrol point my function found. The “IsValid?” function was also a failsafe method to make sure that I wouldn’t get any errors of the system getting array indexes that didn’t exist. (and that happened a lot before…)

Next I made sure the cube would look at the patrol point and proceed to move towards it. The delay loops I’m using are really helpful when you want to make a function be called every frame until it’s done to ONLY THEN proceed to another function, it pretty much makes sure one functon is finished before moving on to the next one. As for the “== (vector)” function I made after the function of moving to the desired location, I’ve made it to make sure it would stop at the patrol point, and the margin of error was set high so it would work anywhere near the patrol point and not EXACTLY ON THE SAME LOCATION OF IT, that’s really important because the smaller the margin of error, the easier it is for my cube to keep going and never stop lol.

Now, on to the functions :3

First off the function for getting the random patrol point. It’s pretty simple, I just got all the actors of my patrol point class and made an array. After that I got the array length and got a random integer between 0 and the length. (User c4tnt pointed out the usage of the length node for getting the number of items inside the array, that’s precisely what I did so kudos to you sir.) Then I just got the object on the array with the index number equal to my newly random generated number and plugged that into the output so I could use it on the casting later. It’s pretty important to use the “IsValid?” node after the function, I was getting a lot of errors since when I didn’t use it I was often getting a number that wasn’t indexed on the array…

NOW TO THIS GUY RIGHT HERE!

This function was what made me work on this program for so much time, I would hide behind the fact that I’m really a newbie when it comes to blueprint programming and I’m learning it because I want to make a game (that will use pretty much a more complex version of this system for NPCs and enemies behavior.), but after learning what I did wrong, I just wanted to hit my head on my keyboard repeatedly because of how plain stupid I was…

This function is pretty simple, I just made a “FindLookAt” node using my cube’s location as the current and the casting vector I got earlier as the target. THE PROBLEM IS THAT I BROKE THE ROTATORS STRUCT PINS AFTER THAT!!! I wanted my cube to just look left or right, so I knew I only wanted to change yaw (Z), HOWEVER, I shouldn’t have done that on my “RInterp To Constant”'s INPUT, it should’ve been on the OUTPUT. Pretty much I was instead of getting the RESULTING Z, trying to ADD UP the UNSOLVED Z’s… don’t make that mistake guys, it’s pretty frustrating.

In conclusion, this was a really fun thing to do and might not seem much for now but it will be REALLY useful when I start working with my city NPCs and stuff, I’ll try to post more answers in this manner on my own posts so that other people looking for answers can get them… or try to, I’m not really good at explaining ;-;

Thanks a lot guys, hope it helps someone!