OnDrawGizmos broken with external behaviours

bdg_toast

New member
When working with a behaviour tree with an external behaviour, gizmos will not work after a reload.

Potentially a bug within `Behavior.CheckForSerialization`, `Behavior.mBehaviorSource` isn't populated properly after a load. I'm seeing `Behavior.mBehaviorSource.RootTask` and `Behavior.mBehaviorSource.DetachedTasks` are null after a reload. I can see `mBehaviorSource = value.BehaviorSource` in the `Behavior.ExternalBehavior` setter, but can't find the equivalent in the loading path after a quick look.
Not going to investigate further as I've already spent way too much time tracking down this bug. Our hotfix while waiting for a proper fix will be to reference `Behavior.externalBehavior.mBehaviorSource` directly in `OnDrawGizmos` if `externalBehavior != null`.

Repro steps for 2021.3.3f1.180:
  1. Create new test action with `OnDrawGizmos` implemented with `Debug.Log` or something equally obvious, we'll call this `TestAction`
  2. Create new empty scene
  3. Add empty gameobject
  4. Open Behavior Designer
  5. Open "Preferences" menu in the Behavior Designer window, change "Gizmos View Mode" to "Always"
  6. With the new gameobject selected, add `TestAction` node, which adds an Entry node, and a Behavior Tree component to the gameobject
  7. Right click in the Behavior Designer editor window, save behavior tree to external behavior
  8. Update Behavior Tree component to use the saved external behavior (sidenote: I feel like this shouldn't need to be done manually, I can see why it might be this way to avoid confusion, but it's annoying for our workflow)
  9. Observe that `TestAction.OnDrawGizmos` is behaving as expected at this point, even when the gameobject isn't selected
  10. Save scene, we'll call this "TestScene"
  11. Create new empty scene (no need to save this one, just forcing a reload)
  12. Load "TestScene"
  13. Observe that `TestAction.OnDrawGizmos` is no longer being called, either by the absence of the actions within that method, or by attaching a debugger and observing that breakpoints within that method are not hit

I've tracked this back to `Behavior.DrawTaskGizmos`, set a breakpoint on the line:
`DrawTaskGizmos(mBehaviorSource.RootTask);`
and observe that `mBehaviorSource.RootTask` is null, and so is `mBehaviorSource.DetachedTasks` (even if your BT has detached tasks).

Cheers,
Brandon

Tech Lead | Toast VR
 
Thanks for the report. Are you running version 1.7.4 of Behavior Designer? I'll give your repro steps a try but just want to confirm.
 
A couple hours before making that post I downloaded and installed the runtime source version from the downloads page, replacing the asset store version we had installed. The welcome window when opening Behavior Designer shows "Version 1.7.2".

So we're either using 1.7.2 (and the runtime source download is a bit out of date) or perhaps the welcome window version text hasn't been bumped?
 
Last edited:
The runtime source download was out of date - if you try it again it'll be the latest.
 
OK so I took some time to try repro with 1.7.4, and the main issue is no longer present, thanks!

One thing I did notice is that if you have "Gizmos View Mode" to "Always", `OnDrawGizmos` won't be called after loading the scene, until you select the gameobject and open the behaviour tree. After which it will work as expected, even after deselecting the gameobject.
 
Top