Runtime serialization/deserialization Variables

jorrit5477

New member
Hi,

New here, currently researching the option to use Behavior Designer for an app. What I'm wondering is if it is possible to serialize/deserialize GlobalVariables and BehaviorTree.Variables to/from a file. The regular UnityEngine.JsonUtility doesn't seem to work (variables have there old values after deserialization), and JSONSerialization is only available in the editor.

Maybe I am missing something, but as I can't find API Reference documentation, I ask here :)

Best,
Jorrit
 
The GlobalVariables are serialized to a ScriptableObject, but I'm guessing that you want the raw JSON output? There isn't support for this at runtime though. What is your goal? I may be able to come up with an alternative.
 
My goal is to save the variables (both global and of one or more behavioral trees) to the file system in json format. Maybe later it could be binary, but I prefer a readable format first for testing purposes.
 
In this case what I think will be the easiest is to loop through the variables and save the values using your own serializer/deserializer. This will give you complete control since the serializer within BD doesn't work at runtime.

You can loop through the values by getting the Variables on the BehaviorSource, and then calling the GetValue on each SharedVariable. When you are wanting to set the values back you can then call SetValue.
 
Top