Andrew900460
New member
I have a few prefabs in my Unity project that have Behavior Tree components on them. And I had worked on making it so each of those prefabs used a particular "External behavior tree". So If I made a change to one, it applied to all the others.
Today I've been making an enemy that spawns other enemies when it dies. And I am having this odd issue where there is a slight lag spike when those enemies are created. I checked with Unity's profiler, and the lag does appear to be coming from the Behavior Tree component when it is first being created. The delay is about 20 milliseconds. Which is quite large. And I am creating multiple enemies at the same time as well.
As an extra sanity test, I made a "bare-bones" prefab with only the B.T. Component attached, and 2 other components that the tree needed (because it uses property maps for some variables. I made a test script to spawn the prefab and looked at its profiler time for instantiation. And this time It only took 2 milliseconds.
Also, I should point out that the times I'm getting in the profile are coming from a "time block" that is labeled "Behavior.Start()" Which I imagine is the Start function in the Behavior Tree Component.
And If I were to disable the B.T. component on my actual enemies, and then spawned them at runtime, there would be no lag spike. Then, while running the game in editor, I could manually enable the B.T. component. When I did that, there was no lag spike. So for some reason, I am getting this 20 millisecond lag spike. And according to the testing I've done, that lag spike can be avoided somehow.
Any ideas why I would get this performance issue? My Ai is simple enough right now that I could've written it as just code in a mono behavior. And I know I wouldn't have any performance issues if I did that.
Today I've been making an enemy that spawns other enemies when it dies. And I am having this odd issue where there is a slight lag spike when those enemies are created. I checked with Unity's profiler, and the lag does appear to be coming from the Behavior Tree component when it is first being created. The delay is about 20 milliseconds. Which is quite large. And I am creating multiple enemies at the same time as well.
As an extra sanity test, I made a "bare-bones" prefab with only the B.T. Component attached, and 2 other components that the tree needed (because it uses property maps for some variables. I made a test script to spawn the prefab and looked at its profiler time for instantiation. And this time It only took 2 milliseconds.
Also, I should point out that the times I'm getting in the profile are coming from a "time block" that is labeled "Behavior.Start()" Which I imagine is the Start function in the Behavior Tree Component.
And If I were to disable the B.T. component on my actual enemies, and then spawned them at runtime, there would be no lag spike. Then, while running the game in editor, I could manually enable the B.T. component. When I did that, there was no lag spike. So for some reason, I am getting this 20 millisecond lag spike. And according to the testing I've done, that lag spike can be avoided somehow.
Any ideas why I would get this performance issue? My Ai is simple enough right now that I could've written it as just code in a mono behavior. And I know I wouldn't have any performance issues if I did that.
Last edited: