Parsing Scriptableobject

What is the best way to iterate through a list of Scriptableobjects?

Using the Introduction to Scriptableobjects session I’ve created a Scriptableobject that contains a list of Scriptableobjects, but now I’m wondering how to reach the information inside each of those objects and create a toggle with that information attached as text. I’d say my programming knowledge is beginner to intermediate.

Thanks for the help in advance.

I’m not sure I understand your question. Iterating a list of anything in C# is the same, scriptable object, plain old object, or even a value type like an integer. You just use a for loop, a foreach loop, or a while, whatever meets your needs.

Well this is the code I’m using currently:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PopulateLightSpells : MonoBehaviour {
  
    public List<SpellList> prefSpellList;
    public GameObject canvas;


  
    void Start ()
    {
        DefaultControls.Resources uiResources = new DefaultControls.Resources();

        foreach(var Spell in prefSpellList)
        {
            GameObject uiToggle = DefaultControls.CreateToggle(uiResources);
            uiToggle.transform.SetParent(canvas.transform, false);
          
            Debug.Log(prefSpellList.Count);
        }
    }
}

This however is only creating one toggle when there are 7 elements in the SpellList that I attached to this.

Are you sure it does not create 7 instances? Check the hierarchy. The snippet does not set any offset (not sure if anything else does) so one might just hide the others, as they seem to be created in the exact same place.

i did think about that, there is just the one. I also have a Vertical Layout Group set for that space where I want them to appear so I would expect that to take effect as well.

Anything in the console?
How often does your log message appear in the console?

Just the once

This definitely shows that the active component’s list contains 1 object. I mean, it’s proven by both, the count that you print and the number of logs that appear.

You should re-check the component again. Perhaps you’ve got an inactive duplicate (or prefab) with 7 objects assigned, whereas the scene contains the one that holds one object.

So I deleted all of the lists i had made so far made a new one and tried again…no change. Thanks for trying to help I’ll play around with it a bit more to see if I can find the problem.

One more idea, what does SpellList look like?
The name suggests it is a list or some other collection on its own, could you post the code for it?

I actually just figured out why its not working, It’s because I was making a new list of spellLists gonna try something slightly different.

Figured out the problem, now just to get all of the info from each of the spells.