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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Image Seq Array sorting issues

Discussion in 'Scripting' started by DANGB, Oct 8, 2015.

  1. DANGB

    DANGB

    Joined:
    Sep 22, 2015
    Posts:
    2
    Hey guys,

    So I have a public Texture array that I am loading an image sequence into.
    I have to load it manually rather than loading it in at runtime through resource.load, as this way stalls the game for several seconds while it loads into the array.

    I am selecting the the entire image sequence and dropping it onto the array in the inspector.
    Up until now they have all been loading in in order and I have had no issues, but for some reason today, when I have gone to load in a new sequence (I am testing different image compression for the image sequence), they have loaded in a completely random order.

    I have gone back and tried loading in my old sequences to test if it was to do with the way it was reading a file type. I have also created a new project with a new script that only has the public texture array in it, to remove any potential interference from other functions in my script. Neither of these have fixed the issue.

    I have done some research and I see there is a way of sorting an array after it has been loaded in, but this is also done at runtime and presents the same issue as using resource.load - its stalls the game while the array is sorted.

    Is there anything I am missing here?? It seems strange to me that this was working fine and then suddenly not.

    Any help would be much appreciated!
     
  2. DANGB

    DANGB

    Joined:
    Sep 22, 2015
    Posts:
    2
    Okay, well I very quickly managed to find a work around for the issue, although I still have no idea why this was happening in the first place!

    Found this great piece of code (C#) that adds a contextual menu to your script and sorts your sequence numerically in the inspector!

    Code (CSharp):
    1. [ContextMenu ("Sort Frames by Name")]
    2.     void DoSortFrames() {
    3.          System.Array.Sort(ImageSequence, (a,b) => a.name.CompareTo(b.name));
    4.          Debug.Log(gameObject.name + ".frames have been sorted alphabetically.");
    5.     }