Serialization NullReferenceException in Unity 2018.4 with Behavior Designer 1.5.7 / 1.6.2

Visulth

New member
I've been getting NullReferenceException errors related to serialization in Behavior Designer, in Unity 2018.4.
This appears to be a similar error to the one posted here last year, but with slightly different context.

I was using BD 1.5.7, and upgraded the project's Scripting Runtime Version from .NET 3.5 Equivalent to .NET 4.x Equivalent.

After that upgrade, I began getting NullReferenceExceptions from Behavior Designer on start up, opening the designer window, runtime, etc.
I then updated BD from 1.5.7 to 1.6.2 to see if that would alleviate the issue and it did not.

Not sure how to fix the issue. (I also have the BD Formations, Movement, and Tactical packages in my project but have not attempted upgrading or modifying them)

Code:
NullReferenceException: Object reference not set to an instance of an object
BinaryDeserialization.LoadTask (BehaviorDesigner.Runtime.TaskSerializationData taskSerializationData, BehaviorDesigner.Runtime.FieldSerializationData fieldSerializationData, System.Collections.Generic.List`1[BehaviorDesigner.Runtime.Tasks.Task]& taskList, BehaviorDesigner.Runtime.BehaviorSource& behaviorSource) (at <00cb1070d60241ceb207182662d41ddd>:0)
BinaryDeserialization.Load (BehaviorDesigner.Runtime.TaskSerializationData taskData, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <00cb1070d60241ceb207182662d41ddd>:0)
BehaviorDesigner.Runtime.BehaviorSource.CheckForSerialization (System.Boolean force, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <00cb1070d60241ceb207182662d41ddd>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.LoadBehavior (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Boolean loadPrevBehavior, System.Boolean inspectorLoad) (at <3275963b2fca4f2ca123754bd86fc27f>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.UpdateTree (System.Boolean firstLoad) (at <3275963b2fca4f2ca123754bd86fc27f>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.OnSelectionChange () (at <3275963b2fca4f2ca123754bd86fc27f>:0)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:342)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:336)
UnityEditor.HostView.OnSelectionChange () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:199)

Code:
NullReferenceException: Object reference not set to an instance of an object
BinaryDeserialization.LoadTask (BehaviorDesigner.Runtime.TaskSerializationData taskSerializationData, BehaviorDesigner.Runtime.FieldSerializationData fieldSerializationData, System.Collections.Generic.List`1[BehaviorDesigner.Runtime.Tasks.Task]& taskList, BehaviorDesigner.Runtime.BehaviorSource& behaviorSource) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BinaryDeserialization.Load (BehaviorDesigner.Runtime.TaskSerializationData taskData, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Runtime.BehaviorSource.CheckForSerialization (System.Boolean force, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.LoadBehavior (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Boolean loadPrevBehavior, System.Boolean inspectorLoad) (at <0f49ef0acdbd44f8a5303100d11f8912>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.UpdateTree (System.Boolean firstLoad) (at <0f49ef0acdbd44f8a5303100d11f8912>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.OnGUI () (at <0f49ef0acdbd44f8a5303100d11f8912>:0)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:342)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:336)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:310)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect, System.Boolean customBorder, System.Boolean floatingWindow, System.Boolean isBottomTab) (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:361)
UnityEditor.DockArea.OldOnGUI () (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:320)
UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:244)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
 
I don't think version 1.5.7 supported .net 4 so that is likely causing the tree's data to get corrupted. I would revert to 1.5.7 and .net 3.5, ensure that works, and then update to 1.6.2. Reserialize the tree and then you should be able to switch to .net 4.
 
Thanks, looks like downgrading from .net 4 to .net 3.5 fixed it, while remaining on 1.6.2. However, I'm now getting a null reference exception when I attempt to start a behavior tree manually via bt.EnableBehavior().

Code:
NullReferenceException: Object reference not set to an instance of an object
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.TaskAddData data)
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.TaskAddData data)
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.TaskAddData data)
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.TaskAddData data)
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.TaskAddData data)
BehaviorDesigner.Runtime.BehaviorManager.EnableBehavior (BehaviorDesigner.Runtime.Behavior behavior)
BehaviorDesigner.Runtime.Behavior.EnableBehavior ()
ZombieNPC.OnStartIsMaster () (at Assets/_Scripts/_NPC/ZombieNPC.cs:115)
NPC.Start () (at Assets/_Scripts/_NPC/NPC.cs:88)
ZombieNPC.Start () (at Assets/_Scripts/_NPC/ZombieNPC.cs:109)

The bt variable is not null as I can access the other fields like bt.name, or bt.BehaviorName, bt.BehaviorDescription, or even bt.DisableBehavior. Enabling it seems to be what causes the error.

Secondly, if I were to downgrade BD from 1.6.2 to 1.5.7 where would I get the older version from? And were I to then upgrade to .net 4 is there a specific trigger to reserialize the tree before upgrading? Or just toggle the serialization options from binary to json and back?
 
If you import the runtime source the stack trace will have more details, but at first guess it could be related to:


Secondly, if I were to downgrade BD from 1.6.2 to 1.5.7 where would I get the older version from?
There isn't a versioning system on the Asset Store so the only way would be to get it from a backup (such as a repository commit) of your project. I don't think you'll need to do this though as it looks like you got past the major hurdle.

And were I to then upgrade to .net 4 is there a specific trigger to reserialize the tree before upgrading? Or just toggle the serialization options from binary to json and back?
That'll do it, or just move a task around.
 
Top