We have some performance issues in our game which are related to nodecanvas. We have NPC’s in our game and they all use a behaviourtree as AI. They’re fairly simple, just running around or talking to each other. Now we also have an option to pause the game but we don’t use timescale for this (we still want to be able to make some logic work) we have an IPausable interface which pausable entities inherit from and then they pause themselves.
This works perfectly , and the behaviourtrees do indeed pause. We have however , very big lagspikes on the frames where we pause and unpause ( 60 fps to 10 fps)and we have traced this back to nodecanvas. The way we pause our npcs is , we call behaviourtreeOwner.PauseBehaviour() and unpause by calling startbehaviour. This pauses all behaviourtrees but somewhere in the nodecanvas code there is a method that calls “FindObjectsOfType” every time you do one of these actions , which causes massive overhead. Is there another way of pausing behaviourtrees? or is there a way in which we can rewrite nodecanvas to not have to always call this FindObjectsOfType. I found this call using the deep profiler . I think it is the GlobalBlackboard Find() function that gets called on awake when we pause/unpause agraph , right? I’m not sure.
I found out some more about the problem , it’s not the globalblackboard. It only gets caused in editor apparently , i checked performance during build and this didnt have spikes. I’ve attached a deep profiler log of the problem.
Indeed your finding is correct 🙂
This is an editor only lag spike when there are a lot of Graphowner, that was introduced in the last version (and will be removed in the next one). The cause of this lag spike in the editor, is only so that the hierachy icons of GraphOwners in the editor, change when the behaviour is paused/unpaused, or enabled/disabled, which certainly does not worth the lag spike.
If you want to quickly fix this, please open up GraphOwnerInspector.cs and comment out line #19, which reads: GraphOwner.onOwnerBehaviourStateChange += delegate { EditorApplication.RepaintHierarchyWindow(); };
That will take care of the lag spike, but also the hierarchy icons changing.
Thanks!