Reply To: Slow instantiation of gameobject -help!

NodeCanvas Forums General Discussion Slow instantiation of gameobject -help! Reply To: Slow instantiation of gameobject -help!

#11743
Gavalakis
Keymaster

Hello,

The reason why this is happening is not about performance, but relevant to how Behaviour Trees work in general.
Behaviour Trees are only updated (Ticked) once per frame. So this basically means that each task’s (action/condition) Execute or Update method will have the chance to be called at most once per frame as well. This is just how BTs work.
So in your BT image above, what is happening is that only one instantiation is taking place per frame too, which also makes sense of the math you provided, in that 100 objects are instantiated within 2 sec, with 2 sec. being 120 frames more or less.

For your case, I’d really like to suggest that you instead simply create a custom Action Task to perform the for-loop tile instantiation and optionally use parameter too.
Just a small example to clarify:

With such a self-contained action you can now also use it as a modular block of code within any BT (or FSM), instead of visual scripting a for-loop with a BT.
Let me know if that helps.
Thanks!

Join us on Discord: https://discord.gg/97q2Rjh