NodeCanvas Forums › Support › Errors trying to restore blackboard variables (using object pooling)
[Edit – i hate this editor]
I’m trying to use Unity’s object pool. I was having weird results and I read in a post (not sure if here or on the Unity forum) that I must serialize the blackboard on creation then deserialize that on subsequent uses from the pool.
First time after being created:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
GridElement - OnEnable - *** serialized blackboard for (3,2)->(3,2)/-263526/GamePiece { "_variables": { "moveYourself": { "_propertyPath": "GamePiece.MoveYourself", "_name": "moveYourself", "_id": "48925e02-f8b4-4f1e-8739-7767174dbcbd", "$type": "NodeCanvas.Framework.Variable |
1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]”
},
“deleteYourself”: {
“_propertyPath”: “GamePiece.DeleteYourself”,
“_name”: “deleteYourself”,
“_id”: “9090a6ff-8d2c-466c-a1d5-770c7aecc0de”,
“$type”: “NodeCanvas.Framework.Variable1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]”
}
}
}
Object is used then released back to the pool
Next time it is pulled from the pool:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
GridElement - OnEnable - *** deserializing blackboard for (3,0)->(3,0)/-263526/GamePiece { "_variables": { "moveYourself": { "_propertyPath": "GamePiece.MoveYourself", "_name": "moveYourself", "_id": "48925e02-f8b4-4f1e-8739-7767174dbcbd", "$type": "NodeCanvas.Framework.Variable |
1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]”
},
“deleteYourself”: {
“_propertyPath”: “GamePiece.DeleteYourself”,
“_name”: “deleteYourself”,
“_id”: “9090a6ff-8d2c-466c-a1d5-770c7aecc0de”,
“$type”: “NodeCanvas.Framework.Variable1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]”
}
}
}
Results in these 3 errors:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
(Blackboard Error): Can't cast value 'False' to blackboard variable of name 'moveYourself' and type 'Boolean' UnityEngine.Logger:Log (UnityEngine.LogType,string,object,UnityEngine.Object) ParadoxNotion.Services.Logger:ForwardToUnity (UnityEngine.LogType,object,string,object) (at Assets/Imported/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:116) ParadoxNotion.Services.Logger:Internal_Log (UnityEngine.LogType,object,string,object) (at Assets/Imported/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:108) ParadoxNotion.Services.Logger:LogError (object,string,object) (at Assets/Imported/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:61) NodeCanvas.Framework.IBlackboardExtensions:SetVariableValue (NodeCanvas.Framework.IBlackboard,string,object) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/IBlackboardExtensions.cs:133) NodeCanvas.Framework.IBlackboardExtensions:OverwriteFrom (NodeCanvas.Framework.IBlackboard,NodeCanvas.Framework.IBlackboard,bool) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/IBlackboardExtensions.cs:227) NodeCanvas.Framework.Blackboard:Deserialize (string,System.Collections.Generic.List |
1<UnityEngine.Object>,bool) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/Blackboard.cs:102)
GridElement:OnEnable () (at Assets/Scripts/GridElements/GridElement.cs:124)
GridElement:Setup (GridElementTemplate,ElementLocation,UnityEngine.Vector3) (at Assets/Scripts/GridElements/GridElement.cs:181)
GridManager:CreateNewGamePiece (int,int,MatchType,string,bool) (at Assets/Scripts/GridManager/GridManager.cs:363)
GridManager:CreateNewGamePiece (int,int,Match,bool) (at Assets/Scripts/GridManager/GridManager.cs:326)
GridManager:FillEmpties () (at Assets/Scripts/GridManager/GridManager.cs:819)
NodeCanvas.Tasks.Actions.MainLoopInitTask:OnExecute () (at Assets/Scripts/NodeCanvasTasks/MainLoopInitTask.cs:18)
NodeCanvas.Framework.ActionTask:Execute (UnityEngine.Component,NodeCanvas.Framework.IBlackboard) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Tasks/ActionTask.cs:93)
NodeCanvas.Framework.ActionList:OnUpdate () (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Tasks/ActionList.cs:101)
NodeCanvas.Framework.ActionTask:Execute (UnityEngine.Component,NodeCanvas.Framework.IBlackboard) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Tasks/ActionTask.cs:95)
NodeCanvas.StateMachines.ActionState:OnUpdate () (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/Nodes/ActionState.cs:44)
NodeCanvas.StateMachines.ActionState:OnEnter () (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/Nodes/ActionState.cs:41)
NodeCanvas.StateMachines.FSMState:OnExecute (UnityEngine.Component,NodeCanvas.Framework.IBlackboard) (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/FSMState.cs:88)
NodeCanvas.Framework.Node:Execute (UnityEngine.Component,NodeCanvas.Framework.IBlackboard) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Node.cs:297)
NodeCanvas.StateMachines.FSM:EnterState (NodeCanvas.StateMachines.FSMState,NodeCanvas.StateMachines.FSM/TransitionCallMode) (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/FSM.cs:171)
NodeCanvas.StateMachines.FSM:OnGraphUpdate () (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/FSM.cs:80)
NodeCanvas.Framework.Graph:UpdateGraph (single) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Graph.cs:684)
NodeCanvas.Framework.Graph:UpdateGraph () (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Graph.cs:677)
ParadoxNotion.Services.MonoManager:Update () (at Assets/Imported/ParadoxNotion/CanvasCore/Common/Runtime/Services/MonoManager.cs:98)
<pre><code>(Blackboard Error): Can't cast value 'False' to blackboard variable of name 'deleteYourself' and type 'Boolean'
UnityEngine.Logger:Log (UnityEngine.LogType,string,object,UnityEngine.Object)
ParadoxNotion.Services.Logger:ForwardToUnity (UnityEngine.LogType,object,string,object) (at Assets/Imported/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:116)
ParadoxNotion.Services.Logger:Internal_Log (UnityEngine.LogType,object,string,object) (at Assets/Imported/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:108)
ParadoxNotion.Services.Logger:LogError (object,string,object) (at Assets/Imported/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:61)
NodeCanvas.Framework.IBlackboardExtensions:SetVariableValue (NodeCanvas.Framework.IBlackboard,string,object) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/IBlackboardExtensions.cs:133)
NodeCanvas.Framework.IBlackboardExtensions:OverwriteFrom (NodeCanvas.Framework.IBlackboard,NodeCanvas.Framework.IBlackboard,bool) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/IBlackboardExtensions.cs:227)
NodeCanvas.Framework.Blackboard:Deserialize (string,System.Collections.Generic.List</code></pre>
1<UnityEngine.Object>,bool) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/Blackboard.cs:102)
GridElement:OnEnable () (at Assets/Scripts/GridElements/GridElement.cs:124)
GridElement:Setup (GridElementTemplate,ElementLocation,UnityEngine.Vector3) (at Assets/Scripts/GridElements/GridElement.cs:181)
GridManager:CreateNewGamePiece (int,int,MatchType,string,bool) (at Assets/Scripts/GridManager/GridManager.cs:363)
GridManager:CreateNewGamePiece (int,int,Match,bool) (at Assets/Scripts/GridManager/GridManager.cs:326)
GridManager:FillEmpties () (at Assets/Scripts/GridManager/GridManager.cs:819)
NodeCanvas.Tasks.Actions.MainLoopInitTask:OnExecute () (at Assets/Scripts/NodeCanvasTasks/MainLoopInitTask.cs:18)
NodeCanvas.Framework.ActionTask:Execute (UnityEngine.Component,NodeCanvas.Framework.IBlackboard) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Tasks/ActionTask.cs:93)
NodeCanvas.Framework.ActionList:OnUpdate () (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Tasks/ActionList.cs:101)
NodeCanvas.Framework.ActionTask:Execute (UnityEngine.Component,NodeCanvas.Framework.IBlackboard) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Tasks/ActionTask.cs:95)
NodeCanvas.StateMachines.ActionState:OnUpdate () (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/Nodes/ActionState.cs:44)
NodeCanvas.StateMachines.ActionState:OnEnter () (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/Nodes/ActionState.cs:41)
NodeCanvas.StateMachines.FSMState:OnExecute (UnityEngine.Component,NodeCanvas.Framework.IBlackboard) (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/FSMState.cs:88)
NodeCanvas.Framework.Node:Execute (UnityEngine.Component,NodeCanvas.Framework.IBlackboard) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Node.cs:297)
NodeCanvas.StateMachines.FSM:EnterState (NodeCanvas.StateMachines.FSMState,NodeCanvas.StateMachines.FSM/TransitionCallMode) (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/FSM.cs:171)
NodeCanvas.StateMachines.FSM:OnGraphUpdate () (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/FSM.cs:80)
NodeCanvas.Framework.Graph:UpdateGraph (single) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Graph.cs:684)
NodeCanvas.Framework.Graph:UpdateGraph () (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Graph.cs:677)
ParadoxNotion.Services.MonoManager:Update () (at Assets/Imported/ParadoxNotion/CanvasCore/Common/Runtime/Services/MonoManager.cs:98)
And
1 2 3 |
NullReferenceException: Object reference not set to an instance of an object NodeCanvas.Framework.Variable |
1+<>c__DisplayClass27_3[T].<InitializePropertyBinding>b__5 (T o) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/Variable.cs:280)
NodeCanvas.Framework.Variable1[T].InitializePropertyBinding (UnityEngine.GameObject go, System.Boolean callSetter) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/Variable.cs:281)
NodeCanvas.Framework.IBlackboardExtensions.InitializePropertiesBinding (NodeCanvas.Framework.IBlackboard blackboard, UnityEngine.Component target, System.Boolean callSetter) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/IBlackboardExtensions.cs:146)
NodeCanvas.Framework.Blackboard.Deserialize (System.String json, System.Collections.Generic.List1[T] references, System.Boolean removeMissingVariables) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Variables/Blackboard.cs:103)
GridElement.OnEnable () (at Assets/Scripts/GridElements/GridElement.cs:124)
UnityEngine.GameObject:SetActive(GameObject, Boolean)
GridElement:Setup(GridElementTemplate, ElementLocation, Vector3) (at Assets/Scripts/GridElements/GridElement.cs:181)
GridManager:CreateNewGamePiece(Int32, Int32, MatchType, String, Boolean) (at Assets/Scripts/GridManager/GridManager.cs:363)
GridManager:CreateNewGamePiece(Int32, Int32, Match, Boolean) (at Assets/Scripts/GridManager/GridManager.cs:326)
GridManager:FillEmpties() (at Assets/Scripts/GridManager/GridManager.cs:819)
NodeCanvas.Tasks.Actions.MainLoopInitTask:OnExecute() (at Assets/Scripts/NodeCanvasTasks/MainLoopInitTask.cs:18)
NodeCanvas.Framework.ActionTask:Execute(Component, IBlackboard) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Tasks/ActionTask.cs:93)
NodeCanvas.Framework.ActionList:OnUpdate() (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Tasks/ActionList.cs:101)
NodeCanvas.Framework.ActionTask:Execute(Component, IBlackboard) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Tasks/ActionTask.cs:95)
NodeCanvas.StateMachines.ActionState:OnUpdate() (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/Nodes/ActionState.cs:44)
NodeCanvas.StateMachines.ActionState:OnEnter() (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/Nodes/ActionState.cs:41)
NodeCanvas.StateMachines.FSMState:OnExecute(Component, IBlackboard) (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/FSMState.cs:88)
NodeCanvas.Framework.Node:Execute(Component, IBlackboard) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Node.cs:297)
NodeCanvas.StateMachines.FSM:EnterState(FSMState, TransitionCallMode) (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/FSM.cs:171)
NodeCanvas.StateMachines.FSM:OnGraphUpdate() (at Assets/Imported/ParadoxNotion/NodeCanvas/Modules/StateMachines/FSM.cs:80)
NodeCanvas.Framework.Graph:UpdateGraph(Single) (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Graph.cs:684)
NodeCanvas.Framework.Graph:UpdateGraph() (at Assets/Imported/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Graph.cs:677)
ParadoxNotion.Services.MonoManager:Update() (at Assets/Imported/ParadoxNotion/CanvasCore/Common/Runtime/Services/MonoManager.cs:98)`
Here’s my code in OnEnable():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
private void OnEnable() { if(this.Blackboard != null) { if (!string.IsNullOrEmpty(_blackboardBackup)) { Utils.Log($"*** deserializing blackboard for {name} {_blackboardBackup}"); this.Blackboard.Deserialize(_blackboardBackup, null); } else { _blackboardBackup = this.Blackboard.Serialize(null, true); Utils.Log($"*** serialized blackboard for {name} {_blackboardBackup}"); } } } |
Any idea what I’m doing wrong?
Stepping through with the debugger, setMethod is null here (Variable.cs) line 280:
if ( prop.CanWrite ) {
try { setter = setMethod.RTCreateDelegate<Action<T>>(instance); } //JIT
catch { setter = (o) => { setMethod.Invoke(instance, ReflectionTools.SingleTempArgsArray(o)); }; } //AOT
if ( callSetter ) { setter(_value); }
} else {
setter = (o) => { Logger.LogError(string.Format(“You tried to Set a Property Bound Variable ‘{0}’, but the Bound Property ‘{1}’ is Read Only!”, name, _propertyPath), LogTag.VARIABLE, go); };
}
*SMACKS FOREHEAD*
These are readonly properties.
Perhaps a null check on setMethod before trying to use it is in order?
Hey,
Oh I see. The setMethod is in a try/catch block and the .CanWrite property is already checked, so I omitted to check the setMethod for null, but sure I will better add a null check anyways. Thanks.
Join us on Discord: https://discord.gg/97q2Rjh
Do you have any ETA on when this Variable.cs setMethod null check will be added?
I’m having null reference exceptions because of this same issue, on NodeCanvas v3.2.5.
Actually, in my case, the setMethod null reference exception still helped me locate an error in my logic.
I was trying to set a property bound variable that had the following getter/setter:
1 |
get; protected set; |
In this case, I had to remove the “protected” keyword, for NodeCanvas to be able to set the variable correctly.
I still think a null check and extra LogError for that setMethod inside the catch {} block would be helpful, to hint to the user about potential cases like mine above.
Hello,
Hmm. The setMethod is checked for null for some time now. It may be that you are using an older version? :).
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
Hello, Hmm. The setMethod is checked for null for some time now. It may be that you are using an older version? :). Thanks!
I don’t think that’s the case at all, both regarding setMethod being checked for null, and me using an older version of Node Canvas.
As mentioned in a few posts above, I’m using NodeCanvas v3.2.5, the latest version available on Asset Store.
Stepping through with the debugger, setMethod is null here (Variable.cs) line 280:
if ( prop.CanWrite ) {
try { setter = setMethod.RTCreateDelegate<Action<T>>(instance); } //JIT
catch { setter = (o) => { setMethod.Invoke(instance, ReflectionTools.SingleTempArgsArray(o)); }; } //AOT
if ( callSetter ) { setter(_value); }
} else {
setter = (o) => { Logger.LogError(string.Format(“You tried to Set a Property Bound Variable ‘{0}’, but the Bound Property ‘{1}’ is Read Only!”, name, _propertyPath), LogTag.VARIABLE, go); };
}
I’m having this exact issue reported by ccfoo242 (setMethod being null in line 280 from Variable.cs), in specific cases like the one from my post above (trying to set a property-bound variable that had “protected set”).
Hello, Hmm. The setMethod is checked for null for some time now. It may be that you are using an older version? :). Thanks!
Actually, you’re right, I was using an older version.
I just updated Node Canvas in my project (via Package Manager), and there were code updates, including the setMethod null check.
The odd thing is that, based on my project’s version control, I had updated Node Canvas to v3.2.5 circa July 2022.
But the latest version on the Asset Store (from August 29, 2022) is also numbered v3.2.5? That’s what made me confused earlier.
Anyway, thanks for giving me the hint to upgrade Node Canvas. 😀
Hey, sorry for the late reply!
Yes indeed, I’ve made a few very minor changes/fixes but kept the same version number for 3.2.5 on a few occasions. 🙂
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh