I have a bound blackboard with a single variable of type Unity Transform. When I save the blackboard it has a value (i.e. MyGameObject). When I load the blackboard the value becomes null. I have tried save/load in BehaviourTree actions and also in C# code. Same result. This does not happen with Graph Blackboard variables.
I cannot figure out what is going wrong. Seems like a blackboard with one variable of Transform type set to value of a scene gameObject plus myBlackboard.Save() and myBlackboard.Load() should be a no brainer. What am I missing?
Not sure if this is at all related to the issue but in trying to chase the issue I noticed that…
When I save myBlackboard.Save() I get this json back (note “_value”:null ): {"_variables":{"myTransform":{"_value":null,"_name":"myTransform","_id":"837cf83a-55b5-498b-981d-5844ab99bf13","$type":"NodeCanvas.Framework.Variable 1[[UnityEngine.Transform, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}}}
When I serialize the blackboard myself myBlackboard.Serialize(storedGoObjectReferences, false), I get nearly identical json except that is “_value”:1: {"_variables":{"myTransform":{"_value":1,"_name":"myTransform","_id":"837cf83a-55b5-498b-981d-5844ab99bf13","$type":"NodeCanvas.Framework.Variable] 1[[UnityEngine.Transform, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]"}}}
Note: I took out tick mark in the json code above before 1 in NodeCanvas.Framework.Variable] 1 due to interfering with code formatting issues here.
Unfortunately the included Save() and Load() methods are not able to save/load Unity Object references. That is because the Save() and Load() methods save the data to json and then save that json to Unity PlayerPrefs. However, both json only and especially PlayerPrefs are incapable of including the required data for a Unity Object reference. This is why json serialization for Unity Objects always comes in pair with a List(UnityEngine.Object) within which the references are stored. The json, being a string, only holds the index of the reference within that list.
Is your goal to Save and Load the variables for the current game session, or to Save and Load the variables between gaming sessions (like a Save Game system) ?
Thank you for the clarification. Unity serialization is still a mystery to me so when I read the NodeCanvas documentation that “All the variables of a blackboard are able to save and load” I didn’t connect the dots that Unity Object references would not be possible. (Maybe a one-line note on the Blackboard Save & Load documentation page would be helpful to a future newbie like me?)
Yes, I am looking to save variables/state between game sessions, and rather than store a vector I wanted to store a game object reference (i.e. a checkpoint) in case I move the checkpoint during prototyping or even game play between sessions.
I’m not sure if it’s the most elegant solution, or the most performant, but for now I have attached a component to each check point game object that has a persistent GUID, and store a reference to that GUID in the blackboard as a string. On game start, I load the blackboard/saved GUID, find the game object based on that GUID, and use the game object reference from there.