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:
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
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:
- Create new test action with `OnDrawGizmos` implemented with `Debug.Log` or something equally obvious, we'll call this `TestAction`
- Create new empty scene
- Add empty gameobject
- Open Behavior Designer
- Open "Preferences" menu in the Behavior Designer window, change "Gizmos View Mode" to "Always"
- With the new gameobject selected, add `TestAction` node, which adds an Entry node, and a Behavior Tree component to the gameobject
- Right click in the Behavior Designer editor window, save behavior tree to external behavior
- 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)
- Observe that `TestAction.OnDrawGizmos` is behaving as expected at this point, even when the gameobject isn't selected
- Save scene, we'll call this "TestScene"
- Create new empty scene (no need to save this one, just forcing a reload)
- Load "TestScene"
- 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