1

enter image description here So I have a little question I'm creating scriptable objects first time from spreadsheet data trying to use the database to automagically make them...

for (int m = 0; m < myAssets.Count; m++)
            {
               Drill_WordBase newWordAsset = ScriptableObject.CreateInstance<Drill_WordBase>();

                // overwrite the defaults with the json data
                newWordAsset.word = word;
                    newWordAsset.isTrue = false;
                    myList.Add(newWordAsset);

                AssetDatabase.CreateAsset(newWordAsset, "Assets/DrillWords/" + newWordAsset.name);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                EditorUtility.FocusProjectWindow();
                Selection.activeObject = newWordAsset;
            }

it "partly works" however I don't understand how to get it to save the files properly. Since in the Assets/Drill_Words/ folder there is some kind of file there but not a scriptable object with all of the info (see pic) However, the DrillWords list has scriptable objects, I haven't yet tested if they have all the data, I lose these scriptable objects after stopping playing?

Any idea what I am doing wrong, how to I save them?

With thanks - N

StackBuddy
  • 577
  • 5
  • 17

3 Answers3

2

You cannot save scriptable objects during runtime. Use an editor script instead.

Otherwise, if you are loading a "spreadsheet" in runtime as part of the application/game, use JSONUtility instead to serialize and deserialize common [Serializable] classes and structs with [SerializeField] instead.

DoctorPangloss
  • 2,994
  • 1
  • 18
  • 22
2

I don't know if you have solved it.

However, you were doing right, you only missed this:

AssetDatabase.CreateAsset(newWordAsset, "Assets/DrillWords/" + newWordAsset.name + ".asset");
ProtoTyPus
  • 1,272
  • 3
  • 19
  • 40
0

As per the latter, this works and operates during runtime.

void Start()
{
    createScriptableObject();
}

void createScriptableObject()
{
    CustomClass newItem = ScriptableObject.CreateInstance<CustomClass >();
    newItem.name = "name";
    AssetDatabase.CreateAsset(newItem, "Assets/NewScriptableClasses/Test.asset");
}
user507095
  • 31
  • 4