Let's say we have a simple MonoBehaviour component which has reference to BehaviorTree component on an NPC and does this (caches NPC rotation speed):
In a scenario where there are 70 NPCs, spawning across 15 frames - 4-5 NPCs a frame, in each frame this code takes 30-46ms to compute and has 24000-30000 calls to GC with 1.1-1.4MB allocation. There is also a setting of patrol waypoints lists, and it takes the same amount of cpu effort to complete (in addition to this reading).
All these NPCs are a ~5 prefabs with BehaviorTree component on them and ~5 respective external behaviors assets assigned directly, there is no pooling or dynamic assignment of trees. NPCs are pooled as is.
I'm assuming this is not per design, but what can be done to make this right? Any insights and tips will be greatly appreciated.
C#:
void Start()
{
MaxLookAtRotationDelta = (SharedFloat)behaviorTree?.GetVariable("MaxLookAtRotationDelta");
}
In a scenario where there are 70 NPCs, spawning across 15 frames - 4-5 NPCs a frame, in each frame this code takes 30-46ms to compute and has 24000-30000 calls to GC with 1.1-1.4MB allocation. There is also a setting of patrol waypoints lists, and it takes the same amount of cpu effort to complete (in addition to this reading).
All these NPCs are a ~5 prefabs with BehaviorTree component on them and ~5 respective external behaviors assets assigned directly, there is no pooling or dynamic assignment of trees. NPCs are pooled as is.
I'm assuming this is not per design, but what can be done to make this right? Any insights and tips will be greatly appreciated.