So currently I have a blueprint that handles when the player is in sight of the AI, it will chase it but I’m not sure how to handle when the player is out of sight, the AI will walk around a bit to look for the player and go back to their original point. Any ideas on how to achieve this?
I think this is what you are looking for
https://forums.unrealengine.com/showthread.php?59262-AI-Project-Sample-(Blueprint-Only)
What you essentially want is another behaviour for your AI that is something like a patrol, or perhaps a behaviour that will make the AI go and look at the last point it saw the player at.
So you have a behaviour tree and a branch that deals with following the player.
The next steps should be relatively simple. What you want to do it place a service on flow control node (a sequence or selector) that is above both of these branches. The service will constantly look to see if the AI can see the player, and if it can it will set a state on the blackboard to ‘chase player’ for example. If not, it will set the state to ‘patrol’.
So first you’ll need a state - this will be a new enumeration type that you will make. Inside you can put any number of states - for this example we will add in the ‘chase player’ and ‘patrol’ values.
Now in your bot’s blackbaord, add a new variable of the type you just made (note - NOT an enumeration base-type, but the type of enumeration you just made. For example you may have called it bot_state).
Now in your service you’ll want to use the receive tick event node to constantly do your calculation - is the player in the bots cone of vision or not? Then set the state to the appropriate thing.
To set the state, you’ll want to create a new variable in the service of type ‘blackboard key selector’ and name it whatever you want, but ‘state’ would make sense. Make it publicly accessible (the little eye symbol). Now drag of it’s pin and search for a node called ‘set blackboard value as enum’ and set it to the state you desire. Back in the behaviour tree select the service node and make sure that this key selector you just made is set to the right value in your blackboard (bot_state). they are now linked. (note you may need to compile the blueprint before it appears there).
OK Phew! almost done. all that is left now is to force each branch of the tree to only fire with the correct state. You want to put a blackboard value decorator on the root of each branch and simply set the options to look at the state value in the blackboard, ‘Is Equal To’ and then the appropriate value.
You may also want to set the flow control options to ‘aborts self’ on ‘result change’. This last part means it will abort out of the active branch if the state suddenly changes (meaning that the bot will behave as if interrupted)
It may sound like a lot, but once you do it once you’ll see it’s a pretty simple set up.