open-behavior-trees
open-behavior-trees copied to clipboard
NullReferenceException whenever trying to save a blackboard in Unity 2023
When using Open Behavior Trees under Unity 2023.3.0b2, the following output gets generated when clicking save on a behavior tree blackboard
NullReferenceException: Object reference not set to an instance of an object
OpenBehaviorTrees.BehaviorTreeEditorUtilities.GenerateAssetCopy (OpenBehaviorTrees.BehaviorTreeNode currentNode, OpenBehaviorTrees.BehaviorTreeNode parent, System.Collections.Generic.Queue`1[T] order) (at ./Library/PackageCache/com.sterberino.open-behavior-trees/Editor/BehaviorTreeEditorUtilities.cs:231)
OpenBehaviorTrees.BehaviorTreeEditorUtilities.GenerateAssetCopy (OpenBehaviorTrees.BehaviorTreeNode currentNode, OpenBehaviorTrees.BehaviorTreeNode parent, System.Collections.Generic.Queue`1[T] order) (at ./Library/PackageCache/com.sterberino.open-behavior-trees/Editor/BehaviorTreeEditorUtilities.cs:215)
OpenBehaviorTrees.BehaviorTreeEditorUtilities.GenerateAssetCopy (OpenBehaviorTrees.BehaviorTreeNode currentNode, OpenBehaviorTrees.BehaviorTreeNode parent, System.Collections.Generic.Queue`1[T] order) (at ./Library/PackageCache/com.sterberino.open-behavior-trees/Editor/BehaviorTreeEditorUtilities.cs:224)
OpenBehaviorTrees.BehaviorTreeEditorUtilities.GenerateTreeFromNode (OpenBehaviorTrees.BehaviorTreeNode node) (at ./Library/PackageCache/com.sterberino.open-behavior-trees/Editor/BehaviorTreeEditorUtilities.cs:110)
OpenBehaviorTrees.BehaviorTreeEditorWindow.Save () (at ./Library/PackageCache/com.sterberino.open-behavior-trees/Editor/BehaviorTreeEditorWindow.cs:1071)
OpenBehaviorTrees.BehaviorTreeWindowHeader.Render (UnityEngine.Rect position, System.Single sidebarWidth) (at ./Library/PackageCache/com.sterberino.open-behavior-trees/Editor/BehaviorTreeWindowHeader.cs:63)
OpenBehaviorTrees.BehaviorTreeEditorWindow.OnGUI () (at ./Library/PackageCache/com.sterberino.open-behavior-trees/Editor/BehaviorTreeEditorWindow.cs:235)
I think that this issue is due to renaming the root node. It tries to get a reference to the existing tree using the name of the currently edited tree (which is a copy) via the root node and throws a null reference exception, I will try to fix it as soon as possible (probably tomorrow).
Just did some further testing in an isolated environment and discovered that this is caused by having unattached nodes on the blackboard.
I personally feel those should be preserved even if they're not being used at the moment, but I'm not sure if what I'm currently experiencing is intended functionality or not.
Just did some further testing in an isolated environment and discovered that this is caused by having unattached nodes on the blackboard.
I personally feel those should be preserved even if they're not being used at the moment, but I'm not sure if what I'm currently experiencing is intended functionality or not.
Sorry for the inconvenience, and that I haven't gotten to this yet. I'm in the middle of finals in my last quarter, actually.
When you say unattached nodes, are you referring to instances of BehaviorTreeNode? Because the tree is comprised of runtime copies of the existing ScriptableObject asset nodes. If you are trying to put nodes in the blackboard tree in the inspector, that would not work. You should instead insert the node using the OnInit() or OnStart() methods in BehaviorTreeNode.
That's okay, please don't rush. Hope your finals go well.
As for unattached nodes, I mean nodes in the Node Editor. If you don't connect nodes together, as shown in this screenshot, you get the NullReferenceException error.
My expectation coming in was that I should be able to save the blackboard with such nodes still not hooked up.
That's okay, please don't rush. Hope your finals go well.
As for unattached nodes, I mean nodes in the Node Editor. If you don't connect nodes together, as shown in this screenshot, you get the NullReferenceException error.
My expectation coming in was that I should be able to save the blackboard with such nodes still not hooked up.
Oh yes, this is because the behavior tree you are working on in the node editor is a copy of the behavior tree asset (the root node). Those nodes can't have null parents, because they wouldn't be part of the tree. I can add a notification when trying to save a tree with unconnected nodes, but saving the tree without connecting the nodes wouldn't work as it currently stands. I would have to rework the implementation to something that uses explicit edges, I think.
Oh, I see, that makes sense now. Thank you for the explanation. I agree adding a notification would make the editor a bit more user friendly to use, and also would most likely be easier to implement, too.
On another note, should I leave this issue open for future reference, or can it be closed?
