Loading Runtime-Generated ScriptableObjects
Posted: Wed May 05, 2021 11:24 pm
Hi,
I'm just getting going with this asset. So far its been great but I've hit a snag. I'm having trouble serializing a fairly complex component.
I'm working on a card game, and I have a Deck component I'm trying to save/load. The deck has a list of Cards (a non-MonoBehaviour c# class), and each card in the list has a scriptable object called CardData, which has nested CardEffect scriptableobjects. The CardData is a runtime-instantiated copy of the base CardData asset for the card, because each card's effects can change over the course of the game, so they can't all share the same scriptable object.
When I LoadInto the Deck component, the list of cards saves/loads fine, and the serialized reference to the CardData is preserved, but neither the CardData scriptable object nor its nested child scriptable objects are saved by value, so if a scriptable object's value is changed or the object is deleted, loading the deck component doesn't restore the CardData's original values or create it if it doesn't exist.
I've gotten ScriptableObjects to save/load fine in other cases in this project. I'm not sure what I'm doing wrong here. I've created a UserType for the Card class, and I'm using a ES3Settings with ReferenceMode.ByRefAndValue.
Some guidance on how to approach this complex serialization challenge would be greatly appreciated. Is there a way to load the value of ScriptableObjects referenced in fields of a loaded component?
I'm just getting going with this asset. So far its been great but I've hit a snag. I'm having trouble serializing a fairly complex component.
I'm working on a card game, and I have a Deck component I'm trying to save/load. The deck has a list of Cards (a non-MonoBehaviour c# class), and each card in the list has a scriptable object called CardData, which has nested CardEffect scriptableobjects. The CardData is a runtime-instantiated copy of the base CardData asset for the card, because each card's effects can change over the course of the game, so they can't all share the same scriptable object.
When I LoadInto the Deck component, the list of cards saves/loads fine, and the serialized reference to the CardData is preserved, but neither the CardData scriptable object nor its nested child scriptable objects are saved by value, so if a scriptable object's value is changed or the object is deleted, loading the deck component doesn't restore the CardData's original values or create it if it doesn't exist.
I've gotten ScriptableObjects to save/load fine in other cases in this project. I'm not sure what I'm doing wrong here. I've created a UserType for the Card class, and I'm using a ES3Settings with ReferenceMode.ByRefAndValue.
Some guidance on how to approach this complex serialization challenge would be greatly appreciated. Is there a way to load the value of ScriptableObjects referenced in fields of a loaded component?