Is there a way to force SortingGroups update via script

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

I filed an issue for this and Unity replied that for optimization reasons SortingGroups were only updated on LateUpdate. They did though add API support for updating sorting groups via script call, should be supported by latest 2018.4, 2019.4 and I assume 2020 versions.