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. Dismiss Notice

Question sprite changes sort order randomly issue

Discussion in '2D' started by Mike01923, Dec 1, 2020.

  1. Mike01923

    Mike01923

    Joined:
    Jun 19, 2015
    Posts:
    190
    In the example clip, you can see when a bunch of sprites clump together, they start to pop in front and behind each other. They are all on the same sorting layer. It's my understanding that each sprite is given a hidden ID on instantiation which determines their order in the layer and doesn't change. So what's happening here?

    Video clip: https://imgur.com/a/hWkU2gC
     
  2. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    its not a hidden id, its labeled as order in layer in the inspector

    this happens when all sprites have the same order, you should set the order you want them to be in
     
  3. Mike01923

    Mike01923

    Joined:
    Jun 19, 2015
    Posts:
    190
    I mean if two sprites have the same sorting layer and order, the engine will randomly select one to be sorted above the other based on a hidden ID that doesn't change. If I'm spawning many instances of the same object, it isn't really feasible to give each one a different order in their respective sorting layer. I've never seen that done, is that common practice?
     
  4. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    yes, you should give different orders in layer to instantiated objects if they overlap, not doing so will produce the glitching displayed in your video. How should unity know which object sorts above the other if you dont tell it yourself