Keep data created at runtime in ScriptableObjects?
I have a few ScriptableObjects that represent different items with properties in my project. These ScriptableObjects are referenced in a few lists in the scene, and called when needed to keep them in memory.
For a few different reasons, I need every ScriptableObject in my project to have a unique ID. I've noticed that modifying a ScriptableObject data at runtime modifies the Asset in the project explorer such that in repeated plays, I can use the same property again and again.
I've written a script that assigns a unique ID to every ScriptableObject. I just need to run this code once, so I've simply referenced the lists and run it on a separate scene to fill every ScriptableObject with a unique System.Guid. This changes the Asset in the editor and I can use the unique ID afterwards in repeated plays inside the editor.
However, my runtime-generated unique ID disappears after compilation or after closing and opening the editor. My question is: How can I keep my runtime-generated IDs inside the ScriptableObject for repeated use?
Answer by PhonArt · Nov 21, 2018 at 07:32 PM
Hello, ScriptableObject save only works in Unity Editor. When you'll build the project, scriptable objects won't be saved anymore. Anyway, have you tried to store the unique ID in a string instead of inside System.Guid ?
I recommand this tutorial on scriptable objects taht will explain everything : https://www.youtube.com/watch?v=ItZbTYO0Mnw I do also recommand storing datas in a binary file. This will work outside the editor to. I recommand this tutorial : https://www.youtube.com/watch?v=sWWZZByVvlU
I hope that i've answered to your question.
Your answer
Follow this Question
Related Questions
How to save class data(variables) into an asset file in editor ? 1 Answer
How do I show a prefab's public variables in a custom editor when I add it to a gameobject list? 0 Answers
Data persistance between Edit and Play Mode 1 Answer
Best way to serialize a big array of a class 2 Answers
Some help with Data Save/Load would be most appreciated 3 Answers