There isn't much that you can do to get around the initial data structure creation process on first enable.
In this case you should be able to pool ...
The tree structure is the same, but each tree needs to have its own instance of the object in order to hold it's own values for that agent.I need hundreds of copies of the same thing, why do I need to deserialize it hundreds of times over?
It doesn't sound like the tree is deserialized after you do the clone. If the tree is running then the tree would have been deserialized.If I clone a GameObject with a behavior tree on it (which takes ~1ms) it'll work as expected but if I then try to set any tree variable value it'll trigger deserialization ... even though it's already running ... Is that a bug?
Are you using external trees?
... each tree needs to have its own instance of the object in order to hold it's own values for that agent.
It doesn't sound like the tree is deserialized after you do the clone.
That's correct.If I spawn 100 entities the deserialization runs 100 times, If I then remove them to their pool and respawn them it doesn't run again. Is this expected behavior?
All of the fields need to be traversed to match up the shared variables and to ensure the variables are pointing to the correct references. I played with this idea awhile back and found that the slowdown was from the reflection and walking these fields, which unfortunately cannot be avoided. I would love to be proven wrong on this case - since it has been awhile since I last looked at this I'll take another jab at it.I'm just missing the underlying reason why it has to create that instance via (slow) deserialization, could this not be dramatically sped up by cloning after the first deserialization?
I'll take another jab at it.