Using behavior tree to modify Unity ECS entity component data

VaulB

New member
Hi,

I know the ECS version of the behavior tree is under development, but I can't halt my game development because of that. I think it should be possible to use current behavior tree asset, but I don't quite know how. I know there is a way to reference a gameobject in ECS, but how would one reference entity and its components in behavior tree? It would be really helpful to have a sample scene with an example. Has anyone tried to do this?
 
I have not tried doing this so I am hoping that somebody else has experience with it and can respond.

Just for some info I am hoping to get the DOTS version of Behavior Designer out by the (late) summer. I still have a number of features that I need to develop so I can't commit to a specific date yet but I'll post about it when I know. You will not be able to migrate trees from version 1 of Behavior Designer to the DOTS version.
 
Oh that's great! I will definately buy it. It will probably be a few days of work to remake the behavior trees in your new asset, but it will be worth it. I actually got the current behavior tree to work now, but the performance could be better, since I will have at least couple hundred enemies with behavior trees. With around 250 enemies my framerate dropped from 120 to 90. With 0.1s update time i managed to keep it between 100-110. I am doing this in Virtual reality by the way. This is good enough for me now. I can at least create the behavior and test the gameplay loop.
 
Here is how I did it. For some reason I could not paste the code here, so I attached it as txt file. There might be a better way to do it, but at least it works. I wonder if there was a way to set the entity referance directly inside the behavior tree. For example as a global variable.

Note: This implementation works only with spawner. You would need a different approach if the enemy was already at the scene.
 

Attachments

Awesome, and thanks for sharing how you implemented it. The DOTS version will definitely be a lot cleaner :)

It's also funny that you mention wanting to have at least a couple hundred agents. I've been working with agents numbering in the tens or hundreds of thousands so a couple hundred seems extremely low to me right now :D
 
Well I'm still a quite beginner in Unity ECS and game making in general, so I don't know how to optimize everything. Trying to run this game on Quest 3 so, that puts some hard barriers for me. I already implement GPU ECS baker and ECS navigation assets. With those I got around 5000 enemies, with collisions, animations and path finding running steady 120fp on my beefy PC. Didn't even try the limit. On Quest 3 it was steady 70fps with 1000 enemies and still ran 60-70fps with 1300 enemies. I have not yet tried how it works with current behavior tree implementation though, but I have a feeling, that your ECS behavior tree will be very much needed for extra performance.
 
Awesome, and thanks for sharing how you implemented it. The DOTS version will definitely be a lot cleaner :)

It's also funny that you mention wanting to have at least a couple hundred agents. I've been working with agents numbering in the tens or hundreds of thousands so a couple hundred seems extremely low to me right now :D

Great to know that you are working on a DOTS version of Behaviour Trees! Currently in our project we are already using DOTS and current BT version. It's easy to combine both. What we are doing is kinda hybrid approach. We have for example move action, that basically enables and disables component that then solves movement for all the agents in parralel in a system later in frame. This way you can distribute heavy computations and still use BT hierarchy. But still things like conditionals or other actions are being executed using entity manager, if it's just a check let's say if component is enabled. We are using burst jobs in actions too. Thought as BT does not run on burst it takes quite some time with current BT if I would have 1000 agents, just behaviour tree updates takes a lot of time if you woulld have big trees. Something in the order of 1000-2000 nodes for each of 1000 agents.

So the question I have for you, do you use Shedule/SheduleParallel for actions in new DOTS BT? How will it work if you would have conditionals that first need to be checked. Is it possible to parrallel AI logic computation, or you need to go deeper with optimizations, like I mentioned where some actions can be moved to Parallel systems later in frame and some other should be executed in Run() job?

If the tree itself will be run using burst it would already increase performance dramatically I think.

Thanks!
 
I'll do an overview video of how it all works when we get closer to release, but each task runs its own system. For the DOTS task they can use burst. The inner tasks (composites/decorators) are run before the outer tasks (actions/conditionals). I am using the job system mostly for cleanup operations. I haven't figured out a good way to run the tasks within their own job since the dependency can change and also they need to be completely each frame to determine if the system needs to rerun.
 
I am not sure I understood what you meant by running tasks withing their job?

How is this new version gone be faster then the current one in terms of tree performance? If for example you would call only burst jobs in current version for logic.
 
You can use the Entity system without using the job system. Just by using the entity system and having a separation of the data and logic it provides a huge speedup, regardless of which thread the logic is run on. With the current version of Behavior Designer you can reach maybe a thousand trees if you have a basic setup, while with the new system you can easily reach hundreds of thousands.
 
You can use the Entity system without using the job system. Just by using the entity system and having a separation of the data and logic it provides a huge speedup, regardless of which thread the logic is run on. With the current version of Behavior Designer you can reach maybe a thousand trees if you have a basic setup, while with the new system you can easily reach hundreds of thousands.

Got it, so memory management due to using enties and components is much better thus providig better performance. Looking forward to this release!
 
Back
Top