Load list of monobehaviour
Posted: Sun Nov 26, 2023 3:57 pm
Hi
I'm currently reworking my load and save scripts and while I have an idea of how I'd like to change them, I don't know how to implement them properly.
I want to change the current system as I store each value in a separate key. This requires more storage space than I would like. That's why I want to combine the values in a key and save the class directly. (I have already tested it and can save up to 50%...)
My setup:
1. I have a “Script A” with different values (including item data, ScriptableObject B). This script inherits from MonoBehaviour.
2. I have a “ScriptableObject B” with item data. With this script I instantiate a prefab of an element, add the values and add "Script A" as a component to the GameObject.
3. I have a “Script C” with a list and all instances of ScriptA are added to this list.
My problem:
When I save and load the list from ScriptB, ES3 automatically creates an object and adds the component.
What I would like to do:
If possible, I would load the values from “Script A”. These values contain the article data (ScriptableObject B). Using this script, I was able to instantiate the element prefab and then add the Script A component to the instantiated element.
Is there a way to do this?
Another option would be to create a “SaveData” class and put all the values from “Script A” into this class. Then I can instantiate my element, add the component, load the SaveData class and set it to the Script A instance. But that doesn't feel right...
Thank you for an answer in advance.
I'm currently reworking my load and save scripts and while I have an idea of how I'd like to change them, I don't know how to implement them properly.
I want to change the current system as I store each value in a separate key. This requires more storage space than I would like. That's why I want to combine the values in a key and save the class directly. (I have already tested it and can save up to 50%...)
My setup:
1. I have a “Script A” with different values (including item data, ScriptableObject B). This script inherits from MonoBehaviour.
2. I have a “ScriptableObject B” with item data. With this script I instantiate a prefab of an element, add the values and add "Script A" as a component to the GameObject.
3. I have a “Script C” with a list and all instances of ScriptA are added to this list.
My problem:
When I save and load the list from ScriptB, ES3 automatically creates an object and adds the component.
What I would like to do:
If possible, I would load the values from “Script A”. These values contain the article data (ScriptableObject B). Using this script, I was able to instantiate the element prefab and then add the Script A component to the instantiated element.
Is there a way to do this?
Another option would be to create a “SaveData” class and put all the values from “Script A” into this class. Then I can instantiate my element, add the component, load the SaveData class and set it to the Script A instance. But that doesn't feel right...
Thank you for an answer in advance.