Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Getting value out of lists of lists

Discussion in 'Scripting' started by Tohru_Tofu, Apr 27, 2023.

  1. Tohru_Tofu

    Tohru_Tofu

    Joined:
    Feb 15, 2023
    Posts:
    2
    Hello there, I'm new from developing and right now I struggle with making lists, my code contain a lot of variables and I love to stay organize. Right now I'm trying to making lists of lists to replace the old stystem, but I dont have the idea of how to get the value out, thank you so much for helping!! My code look like this:

    [System.Serializable]
    public class serializableClass
    {
    public List<sprite> sampleList;
    }
    public List<serializableClass> nestedList = new List<serializableClass>();
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    Is this a simple syntax question? Start with tutorials on List<T>... it's no different if the T itself is another List<T2> inside of it. It will look something like:

    Code (csharp):
    1. var value = nestedList[ outerIndex].sampleList[ innerIndex];
    There are limitations to what Unity's serialization can present however, with rules about marking stuff as serializable (as you have), etc.
     
    Bunny83 and Tohru_Tofu like this.
  3. Tohru_Tofu

    Tohru_Tofu

    Joined:
    Feb 15, 2023
    Posts:
    2
    Thank you so much! It work very well!