Design & structure of high level director / commander AI

Hi there,

I’m interested in implementing a manager / commander / director AI that is not physically present as a character in the game world.

This AI will be responsible for deciding when to spawn more enemy AI according to conditions in the level, giving broad strategic priorities to AI factions, setting macro objectives for individual AI, etc… Th end goal being something similar to Left 4 Dead’s Director AI or the A-Life system in STALKER.

I’ve searched and found a few mention of this type of a setup in the UE4 forums as a good way to handle larger number of AI & handling AI simulation for off-screen persistent NPCs but very little on how one goes about implementing or structuring it within the UE4 engine’s framework

A couple of basic, high level design questions:

  1. What sort of game object should this high-level, but not physically present AI be? A Pawn without any renderable components? Simply an AIController? Can you have an AIController not associated with a Pawn? The docs say it’s a " non-physical actors that can be attached to a pawn to control its actions" so it’s unclear if it can be of any use if not attached to a Pawn.

  2. How would one have the high-level, strategic AI, send messages to the low-level tacitcal AI? I found this question related to communication. Is that the right track? High level AI could have references to existing, spawned AI Pawns, get their blackboard and write values to it which would then be processed by the AI Pawn’s BT?

  3. Can anyone point me to any links giving more info on implementing this type of a system in Unreal?

Thanks for any and all help!

If you are asking how to implement one, you won’t get an answer here. Unless you find someone who has done it before and will either teach you, or has written a tutorial on it, then you won’t get very far. Essentially, you are going to have to learn basics of how AI works and come up with your own design; one which suits your needs. Once you come up with an overall design, then you can ask smaller and more specific questions on how to do smaller tasks or implement the smaller parts.

I’ve never played STALKER; but I doubt Left 4 Dead’s AI Director needs to give the zombies any messages. The AI Director (not really an expert here) decides when and where to spawn zombies and possibly gives them an initial state (unless they choose a random one themselves; i.e. idling against a wall, in a room, or coming after players). It’s other responsibilities include deciding on ambient sounds to play and music cues to create a narrative and atmosphere for the players. It doesn’t need to tell the zombies what to do. Their own A.I. can do that well on their own; after all they are zombies and don’t need to think.

But to give you some direction:

  1. What sort of object should it be? Are you using Unreal’s Blueprints or C++ itself? If you are doing it in C++, you don’t need to use any of Unreal’s stuff to implement it. You can create or own base class. If you want it capable of using Unreals components you can use the base object. The point of choosing which “game object” to choose is to satisfy the requirements you need. So we can’t answer that for you, because we don’t know what you want. If you don’t need it to render or move, then it is unnecessary to use a pawn. If it doesn’t need to directly control an AI character, it doesn’t need be an AIController.
    You can use whatever you want and ignore whatever it inherits, but this is bad practice. But ask yourself; does it need to actually take control of a pawn? This sounds like it will be unnecessarily complex and a nightmare to program. It’s best to just have it send messages (or set values) to the AIController which either forces it to behave a certain way or gives it other options to consider for its behavior.
    It would be best to examine the AI of other games which might use this system. In the case of Total War, Dawn of War, Starcraft, etc. these games use different levels of AI. The supreme commander is the player input obviously or “commander brain” for computer controlled enemies. These AIs probably function much like a player in that they see as a whole, then just issue commands to their squads just like a player would; but then the squads have their own level of control over how they behave on the micro level.

2 & 3 - Yes, one way to implement it would be to have the command AI set values within a units blackboard, then have the unit base its decisions on those values. Otherwise there are different programming patterns you can look into. It’s best to read about this to decide which suits you best. One book which could help out with this is Matt Bruckland’s Programming Game AI by Example; this one uses C++ and walks you through setting up a messaging system to allow AI to communicate with one another. It might be overkill for what you need though.

The system Matt uses is like this: Sender → Courier → Receiver. The three system type works for this reason: Once the sender sends it, they don’t care how it gets there and don’t want to worry about it. The courier allows two types: immedate messages or delayed messages. If it is immediate, then it sends the message immediately. Otherwise, it sends it after the delay. The receiver then gets the message and deals with it accordingly. But this also assumes multiple senders. Since you only have one, you can skip the middle part and just have your Commander send it to the Unit. Really, this can be implemented many ways and it’s up to you to figure that out.

TL:DR;
What object to use depends on your needs. We can’t tell you because we don’t know your needs. If you don’t need what a pawn offers you, don’t use a pawn. Create your own object or use Unreal very base Object (named Object). By having less stuff in your objects, your game will be better off for it (memory, performance, and design wise).

Essentially you could just set up a struct containing the data you want to send, then send it via function to whatever unit needs it. For example, you could just use Unreals custom event system which can receive data. Since your unit doesn’t care where it came from or has a reason to send something back, this would work. If you do need to send something back, like a success notification, use a function.
If it just needs to change variables; which will affect behavior as you expect it to, then changing values within a blackboard would work.

We can’t tell you how to do what you want; you have to learn that yourself. Once you get there, others can help you with the smaller bits.

One tip: When you get there, if you use large amounts of enemies; don’t actually spawn and destroy your enemies. Deactivate them when dead, reactivate and reinitialize when alive. Read about pooling or reusing resources. Spawning and destroying is expensive.

1 Like

Read this article on Alien: Isolation’s A.I. which goes into detail about how they achieved something similar to what you are trying to do. It basically has a Director A.I. and Entity A.I. which work together to achieve an interesting result:
Alien Isolation A.I.