Open JeremyVansnick opened 6 months ago
Yeah this is a feature I've thought about adding for a while. Being able to see the graph highlights in the pause state would be super useful. Definitely was annoying for me when I was working on a game recently and I needed to pause.
Your solution looks pretty solid. Next time I'm working on Fluid BT I need to do a bundle of small patches and features (will include this and get you a credit). It might be a little bit of time before I get to this but it should happen eventually.
@JeremyVansnick Appreciate this contribution, just getting started with this package and ran into this issue pretty quickly while trying to learn things. Made you're proposed modifications and it's working great 👍
When I pause the editor, the behavior tree shows all the nodes as inactive. This is unpractical because we want to ideally be able to pause and see exactly what our AI is doing at that particular frame.
(I am using Unity 2022.3.22f1) I am surprised this issue hasn't been observed before, since when I look at the code it seems quite logical that there would be a bug there. I don't think it's Unity version related.
The state of activation of visual tasks is set to false inside of the OnGUI() method. This works fine so long as the game is running. But the moment, the game is paused, the OnGUI() method is still running, which means all nodes become inactive.
The solution is to update the state of nodes in a method that runs at the same rate as the Update() function, in this case the EditorApplication.onUpdate. We can't do it in OnGUI because OnGUI() runs many times per frame and is completely unrelated to when the EditorApplication.isPaused is set properly.
=> This snippet is to show the first thing I tried and it doesn't work. It's because EditorApplication.isPaused is not set to true before OnGUI has had the time to run several times already, so the nodes are set to false.
Anyway... here's the proper approach: We print things in OnGUI. But we update values in EditorApplication.onUpdate... And we don't update values when the game is paused.
In BehaviorTreeWindow.cs
In BehaviorTreePrinter.cs
In VisualTask.cs
In NodePrinterController.cs
Now our GUI logic is separated from our value updating logic, and the nodes are keeping their active state even when the game is paused!