Forums › 💬 NodeCanvas › ⚙️ Support › Blackboard deserialization issue
Hiya,
I found a bug/weird behavior that happens during Blackboard deserialization.
In short, in a certain scenario (which I will explain), json value of a serialized variable turns out to be an empty string, which causes the following error:
Exception: No input
ParadoxNotion.Serialization.FullSerializer.fsResult.AssertSuccess () (at Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsResult.cs:82)
ParadoxNotion.Serialization.FullSerializer.fsJsonParser.Parse (System.String input) (at Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/Full Serializer/fsJsonParser.cs:480)
ParadoxNotion.Serialization.JSONSerializer.Internal_Deserialize (System.Type type, System.String json, System.Collections.Generic.List1[T] references, System.Object instance) (at Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/JSONSerializer.cs:104)
ParadoxNotion.Serialization.JSONSerializer.Deserialize[T] (System.String json, System.Collections.Generic.List1[T] references) (at Assets/ParadoxNotion/CanvasCore/Common/Runtime/Serialization/JSONSerializer.cs:70)
NodeCanvas.Framework.Blackboard.SelfDeserialize () (at Assets/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/Blackboard.cs:87)
NodeCanvas.Framework.Blackboard.UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize () (at Assets/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/Blackboard.cs:37)
I think this occurred because of how my prefabs are structured. Namely, I have a prefab called EnemyBase, and other specific enemies are inheriting this prefab. EnemyBase has it’s blackboard, and specific enemies add some more fields to that blackboard. One additional piece of info is that they are all using the same FSM.
The issue happens when I delete a field from a blackboard in the EnemyBase. This causes updates to all the inheriting prefabs, and causes this error, which then reoccurs on Unity project startup as well as throughout working with the project.
The way I managed to circumvent this was this – although I am not sure it’s an actual solution or the problems that it may/may not bring.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public void SelfDeserialize() { _blackboard = new BlackboardSource(); if ( !string.IsNullOrEmpty(_serializedBlackboard) /*&& ( _serializedVariables == null || _serializedVariables.Length == 0 )*/ ) { JSONSerializer.TryDeserializeOverwrite<BlackboardSource>(_blackboard, _serializedBlackboard, _objectReferences); } //this is to handle prefab overrides if ( _serializedVariables != null && _serializedVariables.Length > 0 ) { _blackboard.variables.Clear(); for ( var i = 0; i < _serializedVariables.Length; i++ ) { /* FIX START */ if (_serializedVariables[i]._json == "") { continue; } /* FIX END */ var variable = JSONSerializer.Deserialize<Variable>(_serializedVariables[i]._json, _serializedVariables[i]._references); _blackboard.variables[variable.name] = variable; } } } |
Hey,
Thanks for the information. Indeed adding a variable in a derived prefab (or an instance), changes/overrides the array itself (therefore the number of elements), then deleting a variable from the parent/base prefab does not change the array number in the derived/instace prefabs and that is an issue.
In version 3.3.1 and on, I disabled the ability to Add,Remove, and Re-Order variables in prefab instances for that reason and for safety. However I omitted doing the same for prefab variants. I will add that limitation to prefab variants too at least until I find a better way to handle all this (I have something in mind).
Thanks!
Hey @Gavalakis,
Ah alright, that makes sense.
Is the fix that I scrounged up safe to use long term?
Also is there a way for me to remedy these badly serialized Blackboards? Can I somehow just override the old serialized ones with the new? It can be some weird code entry that I run with once and just remove it later, as far as I’m concerned.
My main concern is that something like this doesn’t cripple the project down the line if it happens again. It seems like an insignificant error, but still, better to check
Or even better, if I can find the files in which this is serialized (if they are human readable), perhaps I could edit them. If it works that way 😀
