Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Member Since 27 May 2013
Offline Last Active Today, 03:58 AM

#5114307 Using one instance of Behaviour Tree for many agents?

Posted by avision on 04 December 2013 - 07:35 AM

On aigamedev you will also find the behaviour tree starter kit. It is fine to learn how they actually work. But basically each entity/agent has it`s own copy of a tree. Basically you want to be able to copy each node in a tree with childs. Then you can always use a subtree in different places. So you can make different trees who share same subtrees. You could then at runtime change a subtree for one agent but not for the others who use the same big root-tree.


Having one instance of a tree working with multiple entities is a bad idea IMO. A BT represents the ai state of one entity. How would you store the state of all the enitites currently using a tree inside the tree? One would be executing a seletor "find cover" while another would be "shoot with machine gun", every node would have to store the state for each entity. The next problem would be that you could not change a subtree for one agent only. Imagine a agent gets a new kind of attack, you would inset a special subtree in an attack subtree, but you can`t cause the other entities don`t have this kind of ability.


Think of the BT as the brain of an entity. You don`t want to share a brain :)

#5114112 Component entity system - create from template

Posted by avision on 03 December 2013 - 01:32 PM

I would probably arrange things differently.. I will try to describe it with examples.

I would use Entities, Components, Nodes and Systems. Ok what are they..


Entity: Could be just a UID

Components: Things like a 3D-mesh component, visibility-component, location in 3d-space component, AI-component ..

Nodes: below..

Systems: Render System, AI-System, Pathfinding-System


When game data is loaded there are basically a set of components describing an entity. Like a mesh-component with the filename and the like and probably an ai-component. The component is only a set of values with some sort of identifier.


Then this set of components is examined. Means all systems check if they want an entity having this _combination_ of components. If the render-system sees a entity having a mesh-component and a visibility component it creats a render-node for this entity and stores this in a list, dictionary, vector or whatever..


On each frame each systems iterates over the nodes it has and does it`s work. If an entity looses a component the systems are notified about that and check if they have to destory/remove the respetive node (Or some other piece of code does this and only notifies the systems loosing a node/entity). For example if a entity looses its visibility-component the render-system may want to remove the render-node but the resources-system may want to keep its resource-node.

In pratice most system will need to share data. So the goal should be to try to group data as much as you can if the data is not shared by multiple systems, if data is shared by multiple systems, spread it in different components. The way systems will store the entites/component-sets will be different from system to system, most systems will probably use a simple list, others will use a different way cause they want to process the nodes with multithreading or have a search tree or whatever.

To identify if an entity has a set of components a component could have an integer-id and the check if a entity has a set of components could be done with bit-masking. (The check which is done when an entity is created and the systems want to know if they "want" this entity).


just my ..