AI Pathing and other AI questions

Hi all.

I have never worked with AI before, aside from rather simple AI Move To and just calling events when the AI is within a certain range of the player. Obviously, when using something like the AI Move To node, the AI moves in a linear path toward the player. There are three problems with this, in my case:

  1. I currently do not have animations applied to the AI’s skeletal mesh so I’m not sure if this issue will persist when I do, but when the AI turns, it’s very choppy - like it’s snapping in increments. It has a very unnatural feel.

  2. What if I want to have the AI have certain movement patterns? For instance, moving in a zigzag pattern rather than a linear path straight toward the player.

  3. What if there are objects in the way that I want the AI to interact with? IE: Opening a door, jumping over a box, jumping through a window, jumping onto and off of a platform, riding up an elevator… etc.

I’ve been solely using Blueprint for what little AI I’ve made so far and at this point I’m beginning to wonder, is it worth it to learn Behaviour Trees? I spent some time watching tutorials on that a while back and was a bit confused and decided to stick with regular BPs. The three main issues above taken into consideration, are Behaviour Trees a better option? What other reasons should I (or should I not) switch to Behaviour Trees over BP?

Lastly, how might I best learn AI for UE4 in general? I’ve been hacking stuff together in BP and making extremely buggy (but somewhat functional) AI for a while and know I’m not doing it right.

For instance, take this monster AI I was working on a few days ago:

Of course, this is not functional yet since it’s still a work in progress. The general idea is that when it’s in the Inactive state (hidden away in the map somewhere, not activated yet), it does nothing. When it’s Passive (it cannot see the player), it just roams around on its own within a certain range of the player (this way it doesn’t just roam around in random parts of the map and the player never encounters it, though that is still theoretically possible… another issue I’m having and could use advice on - more on that later). When it’s Neutral (it can see the player), it will start following the player around. Aggressive and Retreating haven’t been set up yet, but I’ll just explain what the idea is for both of those. When it’s Aggressive, the player has angered it (either gotten too close to it or it’s taken a picture of it [the player has a camera and can take pictures of scenery. Taking pictures of the monster angers it]) and it will start chasing the player faster. Retreating is when the player has injured the monster, and it will start running away.

Here are the problems with what I’ve got so far and what I’m working on:

  • Theoretically, the player could still never encounter the monster in-game. Even though it’s roaming around NEAR the player, that doesn’t guarantee they will encounter it.
  • How would I make the monster give up chasing the player? For instance, if the player hides behind a wall or something - the monster searches around, if it doesn’t find the player, it goes away.
  • Once again - movement patterns. If it’s too linear, being chased would be boring and fighting it off would be too easy. The movement paths and movement speed need to be dynamic - instead of running straight, it zigzags, and during its attack animation, it moves slower (giving the player time to dodge the attack).
  • What about obstacles? The monster is a large bear-like creature (a quadruped as well) and the game takes place in a forest. There are logs and rocks all over the ground - it would make much more sense for the monster to jump over these instead of automatically walking around them. How can I set that up?
  • Making the monster run in the opposite direction of the player and actually avoid the player, and then becoming passive again once it’s gotten far enough away.

Any advice on all of this would be fantastic. This is currently the biggest issue I’m struggling with in all my projects.


I would suggest looking into Blackboards to run AI instead of doing them through BP’s

Here is a nice place to start! Blackboard Documentation - Blueprint Visual Scripting - Unreal Engine Forums