Serialization Error in 2018.3

WillG

New member
Some context. I have used an older version of BD for awhile in Unity 5.6.6. I updated to BD v1.6 and it works fine in 5.6.6.

When I try to run or open an external BT in the BD Editor window in 2018.3 I get a null reference as it tries to deserialize the data. I noticed BD received an update (1.6.1) for 2018.3 support. I deleted the old folder structure and imported the source code package from this site. I then tried to view another BT and I get the same error.

LoadField seems to return null when the fieldType is an int but not assignable to a SharedVariable. This is odd since SharedInt exists in the BehaviorDesigner.Runtime namespace.

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 Assets/ThirdParty/Behavior Designer/Runtime/BinaryDeserialization.cs:319)
BinaryDeserialization.Load (BehaviorDesigner.Runtime.TaskSerializationData taskData, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at Assets/ThirdParty/Behavior Designer/Runtime/BinaryDeserialization.cs:124)
BehaviorDesigner.Runtime.BehaviorSource.CheckForSerialization (System.Boolean force, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at Assets/ThirdParty/Behavior Designer/Runtime/BehaviorSource.cs:76)
BehaviorDesigner.Editor.GraphDesigner.Load (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Boolean loadPrevBehavior, UnityEngine.Vector2 nodePosition) (at <ae691f566f7448529b3a0daf70d70cb7>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.LoadBehavior (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Boolean loadPrevBehavior, System.Boolean inspectorLoad) (at <ae691f566f7448529b3a0daf70d70cb7>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.ReloadPreviousBehavior () (at <ae691f566f7448529b3a0daf70d70cb7>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.OnFocus () (at <ae691f566f7448529b3a0daf70d70cb7>:0)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <ac823e2bb42b41bda67924a45a0173c3>: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 <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <ac823e2bb42b41bda67924a45a0173c3>: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.OnFocus () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:146)
 
I would completely remove the Behavior Designer directory from the Asset Store cache to ensure you are getting the correct version. The serialization hasn't changed in awhile so it should be the same as 1.6.
 
I downloaded the source package from this website and used that instead of going through the asset store. Also this issue occurred in 1.6 on 2018.3, but not in 5.6.6.

So to be clear:
Unity 5.6.6 + 1.6 BD = issue does NOT happen.
Unity 2018.3 + 1.6 BD = issue happens.
Unity 2018.3 + 1.6.1 BD = issue happens.

There are no modifications to the saved external BT trees (as I checked with existing source control versions) as I thought perhaps upgrading to 2018.3 may have modified them.

I've tried deleting my Library folder to reimport everything without success as well.
 
Last edited:
Ah, that's a pretty big jump between 5.6 and 2018.3. Have you tried switching to an intermediate version to see if that works? Such as 2017.4? The jump between 5.6 and 2018.3 probably means that the scripting backend was changed as well as the scripting runtime. BD should have no problems with this as long as it is serialized to the most recent version before you do the jump.

Have you tried switching to json serialization and seeing if that works? Since you've imported the source can you tell why it returns null when an int should be returned? As a temporary work around you could have it just return 0 for that field type.
 
Thanks for the suggestions. Since it seems to work fine with BD 1.6 in 5.6.6, I am going to resave all the saved data there then try it in 2018.3. If not then I will json serialization via the same process.

I've been doing some debugging and the issue seems to be that fieldIndexMap does not contain the fieldHash. As a result it enters the if and tries to create a SharedVariable from it, but the type is an int. An int is not assignable to a SharedVariable type and thus null is returned. So the next step down that path is figuring out why its not a part of the fieldIndexMap. Hopefully some of the other suggestions will work and I won't need to continue down this path. shaHashSerialization is false as well FYI.

Code:
        if (!fieldIndexMap.TryGetValue(fieldHash, out fieldIndex)) {
 
Last edited:
Did some tests. Saving as JSON serialization in 5.6.6 with v1.6 BD then opening it up in 2018.3 v1.6.1 BD works. A little tedious to ensure I get all the saved BT files, but this should get me going. Thanks.

FYI I noticed the previous BD binary saved version was 1.5.7 if you care about that info. Resaving the 1.5.7 as 1.6 in binary also loaded fine in 1.6.1 2018.3. So at least in our case, loading 1.5.7 binary BD data in 2018.3 v1.6 and v1.6.1 BD has the problem.
 
Last edited:
Ahh, 1.5.7 was the issue. The latest version drops support for that so you would first need to reserialize it was a version prior to 1.6 in order for it to work. I'm not sure why 1.6 works but if you reserialize the tree while in Unity 5.6 to BD 1.6 then it should work in Unity 2018.3.
 
Top