Making AI pick random point of interest

Hi!
I’m trying to create an AI character that picks a point of interest and walks to it.
I created a blueprint class based on the TargetPoint class called “PointOfInterest”. My wish is to be able to place these in the level. The AI Task casts to the class, creates an array of all objects, picks a random, gets its vector value, sends that value to the blackboard, and then the Move To node in the behaviour tree does the rest.

Here is the task

Here is the macro

Here is the behaviour tree (I have noticed and fixed the Loaction typo)

And here is the blackboard, if it’s necessary.

Before I started with this, I made it pick a random reachable location and move to it, which worked perfectly. I think the only problem is the logic.

I see a few issues with what you have here. First the oning actor which i guess is the character would not inherit feom point of interest so the cast would always fail. Second your array has one item which is index 0 but your getting the length of the array which is one, this will cause problems and not return the expected values.

To solve these issues i would create a variable of the pointofinterest type somewhere such as on the character then in the task you would just need to drag off the owning actor and cast to its class, then you could get the array directly feom there. Then in your macro you want to jave length minus one then plug that into the random int.

To populate your array you could use a get all of class node, or make the variable public and set the values in the array feom the scene details panel

Apologies for spelling here i wrote this on my phone

So, in the AICharacter blueprint, I create a variable? What kind of variable, actor, target point? And then I cast to the AIcharacter instead to get the array? I can’t find any “cast to AIcharacter” node.

yes in the ai character you would create a variable and its type would be pointofinterest as in the point of interest blueprint that you were trying to cast to before. if you wanted to change your system and use target points or something else then that would be fine as well.

yes you cast to the class of the aicharacter, so if your ai character was of the class “BP_MeleeEnemy” then you would cast to that class. the class needs to be as specific as the variable that your looking to get.

A little basics on casting say you wanted to see if a object was a character then you could just cast to character, but if you wanted to see is it was a specific character with certain attributes such as checking if it was a boss then you would need more defined criteria to compare to so you would cast to bosscharacter class which would be a class that all bosses inherit from.

I can give you a checklist:

  1. First make sure you assign the Blackboard key to the basic task in the behavior tree. You need to make the destination key as public in the Task and assign it a blackboard key in the behavior tree Basic task node.
  2. Make sure Move To Node has everything set right on the details.
  3. Check if Nav mesh is generated by pressing P
  4. Make sure you don’t have any idle root motion or other animations that prevent you from moving.
  5. Take a look at the character velocity, see if the other basic things like Controller is attached to the player (Placed or spawned in the world setting if you remember)

Lastly, I don’t know what the class point of interest is, please make sure the array is populated. in the task node, if not you are not even getting the random points as you expected.

Another tip, UE4 has built in GetRandomPointInRadius or something like that, was pretty useful for my case.

It’s not currently working (in my project, I submitted a bug report for it), but here is a SS. The blueprint is based on a character class (copy 3rd person character, rename to AI character or w/e, delete the camera, camera boon, and stuff in the event graph. The add a navmesh volume to the level, and it should move to a random location within a radius of it’s spawn point.

This is a bit off topic but the issue with your particular script is that your random point is wihin the acceptance radius so every point you get is within the accetable distance to the character. Try removing the variable from the acceptance radius and setting the acceptance radius to sometthing like 50. Have your roam radius set to something like 1000

Also doing this script on tick is a bad idea you want to have more control of how often it fires. Also using other methods will make the script more performant. For instance use a custom event then when the character gets to the target location call the event again

I appreciate the help Savior, but I prefer to use behaviour trees for AI’s, it’s much more practical and easier to add new tasks. Also, I know how to make the character move to a random location, but I need it to move to specific coordinates that I have specified.