Loading list from scriptable object loaded via Resources.Load

Viewed 151

I am trying to load a list of structs from a ScriptableObject which I load with Resources.Load. The Resources.Load call is not returning null, and appears to "load" the scriptable object. I then attempt to retrieve a List of struct from the loaded SO like so :

void LoadCheckpoints(string sceneName){

    CheckpointData attemptLoad = Resources.Load<CheckpointData>("CHECKPOINTDATA/checkpointData" + sceneName);

    if(attemptLoad != null){
        
        data = attemptLoad;
        sceneEntries = data.sceneEntries;

however this list data.sceneEntries will raise a null reference exception. Am I missing something about the use of scriptable objects? Can I not save a list to a scriptableobject and then load it later with resources.load?

1 Answers

I figured this out, for anyone that stumbles on this issue, the struct being stored in the list needs to serializable.

The definition of the struct should look like :

[System.Serializable]
public struct MyStruct {
Related