What’s the proper way to deserialize blackboard variables of custom monobehavior based scripts that are instantiated? I’m getting the following error when attempting to deserialize an object:
InvalidOperationException: An error occured while deserializing asset reference GUID=[7a89880255e2246de83870fb9c1e9803]. Asset is not yet loaded and will result in a null reference.
The documentation made it seem like the IUnityObjectResolver would be called on the agent and all of the blackboard variables to be able to translate things between serializing and deserializing but that appears to not be the case. It seems to only be calling the Map function for the Agent GameObject itself and the rest of the data is serialized using the GlobalObjectId which changes between instantiations and causes that error to be thrown.
It seems like the serialization package’s solution to this is to make custom Adapters to handle the specific types and how it serializes and deserializes. Unfortunately, the built-in behavior JsonBehaviorSerializer does not seem to expose any way to add or modify what Adapters the serialization route is taking. There’s also no way to modify the JsonPackageSerializationParameters (where these adapters are set, as well as additional useful settings like being able to minify the serialized json output to save space in the string)
Is the intention for users to make their own entire JsonBehaviorSerializer class, copying the adapters (because they’re private) in the behavior library and expanding with adapters for their own custom scripts?
I found this previous discussion from October (Behavior: Errors deserializing BehaviorGraph JSON after re-creating related GameObjects) where the end result seems to be a workaround that you unassign all blackboard variables before serialization and restore them afterward. With the way I currently have some of my behavior tree set up (Restart/Abort nodes looking for variable changes) that is not a feasible option for my use case as that would alter the agent’s behavior whenever a save happened.
I’ve got a 100% repeatable project I can file a bug with that’s based off of the serialization example but wanted to see if I’m just going about this wrong or there’s some way to fix the error that I’ve not come across