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

Invalid SortingGroup index set in Renderer

Discussion in '2D' started by Havokki, Nov 21, 2018.

Thread Status:
Not open for further replies.
  1. Havokki

    Havokki

    Joined:
    Jun 28, 2015
    Posts:
    118
    Hi! We are facing an issue with SortingGroups causing crashes. Every now and then when we activate/deactivate a GameObject with a SortingGroup (either in the GameObject itself or any of its children), or when we activate a ParticleSystem under a SortingGroup, the game crashes with this error:

    After that the console is being spammed with this error:
    I have made sure all the sorting layers being set are valid (always setting the same layer and it's working most of the time).

    There are two bugs in the tracker, but they have been marked as fixed long time ago:
    https://issuetracker.unity3d.com/is...hat-has-a-child-gameobject-with-sorting-group
    https://issuetracker.unity3d.com/is...group-id-assert-when-removing-a-sorting-group

    We are using 2018.2.9f1. Currently unable to update to newer versions because of an external plugin that we are required to implement.

    I haven't sent a bug report yet, since I haven't been able to create a reliable reprocase. Still working on that. In the meantime, has anyone else faced this same issue and is there a known fix?

    EDIT:
    Not sure if it matters, but: The SortingGroup components are being added dynamically during runtime. The ParticleSystem under one of the SortingGroups is also being added dynamically from a pool.

    EDIT2:
    Moving the ParticleSystem to be a sibling of the top-most SortingGroup (in the hierarchy, not sorting order) made the crash rarer, but did not completely fix it.

    Also had another case, where it was crashing most of the time and I was able to fix that by first setting the sorting layers and orders, waiting for a frame, and then finally activating the ParticleSystem.
     
    Last edited: Nov 21, 2018
    Tymianek likes this.
  2. ChoiJH

    ChoiJH

    Joined:
    Apr 9, 2016
    Posts:
    2
    i have same issue in 2018.2.11f1 very anoying la;sdkfj a;lwiefj;laksjd fsda
     
  3. ChoiJH

    ChoiJH

    Joined:
    Apr 9, 2016
    Posts:
    2
    ha.. I fix this

    In My Case Do NOT Use Same Time(inRuntime) Change Parent and SetActive Renderer.
     
  4. Kryzarel

    Kryzarel

    Joined:
    Jul 30, 2013
    Posts:
    34
    Not sure if I'm seeing the same issue on my side, but it certainly seems quite similar, which would leave me to believe it is the same as this bug reported on the issue tracker: https://issuetracker.unity3d.com/is...-when-managing-sortinggroups-children-objects

    In our case, we were able to circumvent the issue by disabling the sorting group before reparenting or enabling/disabling any children of the sorting group, then enabling it again afterwards.

    After waaay too many hours tinkering around we finally managed to end up on this easy solution that worked for us. But it is still a crappy workaround and can't wait for Unity to fix the issue properly.

    The worst part is, I can't even figure out the exact circumstances that cause the problem, it seems to happen pretty inconsistently. It's certainly related to parenting/unparenting and enabling/disabling child objects of a SortingGroup. It also seems like waiting at least until "end of frame" (using a coroutine) makes the issue much less frequent.
     
    Last edited: Apr 4, 2019
    Havokki likes this.
  5. xushunwangdh

    xushunwangdh

    Joined:
    Aug 13, 2018
    Posts:
    2
    I have same issue in 2018.4.3f1.

    Also add a particle from a pool to be a child of a sortinggroup gameobject.
     
  6. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,554
    This still happens in 2019.1.12f1
     
  7. unity_NwjSBWdoDScpdQ

    unity_NwjSBWdoDScpdQ

    Joined:
    Jul 30, 2019
    Posts:
    1
    same in 2018.4.4f

    is there a way to debug this? I see it on my console in unity, but no stack track
     
  8. Valorware

    Valorware

    Joined:
    Aug 25, 2016
    Posts:
    88
    Unity 2018.4.2f1 working in 2D, I managed to solve this problem by just adding a sorting group to the problematic pooled object. The new parent of the pooled object had a soprting group too, which overwrited the new "dummy" sorting group of the pooled object anyway, so adding this dummy seemed to cause no sorting issues.


    This worked for me too, by delaying the "setactive" by 1 frame- but this wasn't graceful enough for me.

    For reference, my pooled object was just a spriterenderer with particle system on the game gameobject, stored as a prefab. No sorting group. But adding a sorting group to this prefab seemed to prevent the issue.

    Hope this helps
     
    Ksushqa and Havokki like this.
  9. akianto

    akianto

    Joined:
    Aug 9, 2018
    Posts:
    3
    Hi, I've faced the similar issue. My solution was:

    Code (CSharp):
    1.  
    2.     SortingGroup[] sortingGroups;
    3.     SortingGroup[] SortingGroups => sortingGroups ?? (sortingGroups = GetComponentsInChildren<SortingGroup>());
    4.  
    5.     void OnEnable()
    6.     {
    7.         foreach (SortingGroup sortingGroup in SortingGroups)
    8.             sortingGroup.enabled = true;
    9.     }
    10.  
    11.     void OnDisable()
    12.     {
    13.         foreach (SortingGroup sortingGroup in SortingGroups)
    14.             sortingGroup.enabled = false;
    15.     }
    The script with the similar code should be attached to the root of pooled object.
    Hope, it will help you.
     
  10. Aurigan

    Aurigan

    Joined:
    Jun 30, 2013
    Posts:
    291
    Still happening in 2020.1.10 ... looks like this is caused, for me, by creating an object from a pool and setting one of its children to active in the same frame.

    Happens very infrequently, added a sorting group to the parent object in an attempt to hack around this, will update if this doesn't work.
     
  11. thiagolrosa

    thiagolrosa

    Joined:
    Feb 22, 2017
    Posts:
    57
    Also having this issue with 2020.3.8f1, I will try the solutions mentioned above!
     
  12. bunp

    bunp

    Joined:
    Feb 21, 2019
    Posts:
    66
    I am having this issue in 2020.3..13f1, but the above sollutions did not work for me and I'm not sure why.
     
  13. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Would it be possible to send a bug report with your project using the Unity Bug Reporter and steps on how to reproduce this issue, and post the case number here? Thanks!
     
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,511
    As above, what actually helps is a bug report.

    Please don't assume any problem has one root cause. All too often we see "this is still happening and it's not fixed". Please submit a bug report. We take bug reports very seriously and they are essential to finding the root causes of problems.

    Thanks.
     
  15. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    660
    Unity 2022 still happened I don't know which one created this error or where to fix
     
  16. esco1979

    esco1979

    Joined:
    Mar 18, 2014
    Posts:
    136
    I had this same bug today; I simply switched the line that set the sorting order to be AFTER the line that activated the object. I haven't seen it since.
     
    PokerDawg likes this.
  17. modernator24

    modernator24

    Joined:
    Apr 7, 2017
    Posts:
    168
    Same in 2019.1.0f2 and above versions.
     
  18. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    660
    Oh it still happen in 2022.1.0b2.2474
     
  19. Tymianek

    Tymianek

    Joined:
    May 16, 2015
    Posts:
    94
    Same error 2021.3.11f1
     
  20. weekstonz

    weekstonz

    Joined:
    Sep 1, 2023
    Posts:
    1
    I have same issue in 2018.4.3f1.
     
Thread Status:
Not open for further replies.