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

Is there a way to force SortingGroups update via script

Discussion in '2D' started by matiasticbits, Dec 2, 2019.

  1. matiasticbits

    matiasticbits

    Joined:
    Jan 3, 2017
    Posts:
    30
    We have been having issues with SortingGroups. We have a use case where we want to construct a background scene that contains prefabs with SortingGroups and then render that to a RenderTexture. All this happens in a single frame and single flow of logic. Only problem in this is that SortingGroups do not work in the same frame they are instantiated, so we have to wait for a one frame before calling the camera to render the scene. And this makes things very complicated and causes other issues. I have reported a bug about this to Unity.

    In 2018.3 I noticed Untiy added an experimental API called PlayerLoop. Under this on PostLateUpdate there is a call for a struct named SortingGroupsUpdate. And this is something I would like to want to call directly from code before doing our background rendering. I could create a custom PlayerLoop where this would be called before LateUpdate and I could handle the rendering there. But we also have a use case where we want to render the background, create level objects and then render a minimap of this level and there are some cases where we want to render the minimap for more than one level in one frame. This just means we have a need for running SortingGroupsUpdate multiple times in one frame and not via PlayerLoop.

    I can access the PlayerLoopSystem for SortingGroupsUpdate but I don't know how I could invoke it as only think I a have is the IntPtr reference to the native function. If anyone has an idea how to call this from C# code, please let me know.

    https://docs.unity3d.com/2018.3/Doc...rLoop.PostLateUpdate.SortingGroupsUpdate.html
     
  2. matiasticbits

    matiasticbits

    Joined:
    Jan 3, 2017
    Posts:
    30