Search Unity

Toggling Rendering For An Entire World

Discussion in 'Graphics for ECS' started by spectre1989, Mar 5, 2020.

  1. spectre1989

    spectre1989

    Joined:
    Oct 6, 2009
    Posts:
    125
    Hi all,

    I need to toggle rendering for a world on and off. Ideally, I'd like to avoid having to remove the rendermesh component from every entity. I tried:

    Code (CSharp):
    1. this.World.GetExistingSystem<PresentationSystemGroup>().Enabled = false;
    Strangely this works if I do it when the world is created, but not if it's disabled on the fly.

    Any ideas?
     
  2. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    398
    I think disabling RenderMeshSystemV2 should work.
     
  3. spectre1989

    spectre1989

    Joined:
    Oct 6, 2009
    Posts:
    125
    I tried this

    Code (CSharp):
    1. this.World.GetExistingSystem<Unity.Rendering.RenderMeshSystemV2>().Enabled = false;
    no dice :(
     
  4. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    398
    Is GPU instancing enabled on your materials? I suspect they might be causing it.
     
  5. spectre1989

    spectre1989

    Joined:
    Oct 6, 2009
    Posts:
    125
    No, I'm just creating some basic primitives which all use the built in material "Default-Material"
     
  6. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    398
    Adding FrozenRenderSceneTag without specifying the SceneGUID does it for me.

    Code (CSharp):
    1. EntityManager.AddSharedComponentData(EntityManager.UniversalQuery, new FrozenRenderSceneTag());
     
  7. spectre1989

    spectre1989

    Joined:
    Oct 6, 2009
    Posts:
    125
    Yeah that worked, only issue is it only works for current entities and doesn't apply to any entities created later. But I guess I could write a system to keep track of the current hidden state and add this tag to any new entities each tick.

    It is really strange/annoying that you can't just disable the rendering systems though, I wonder why that is.
     
  8. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    398
    You could do both maybe, add FrozenSceneRendering tag to existing entities to stop their rendering and disable the RenderMeshSystemV2 to prevent new entities from being rendered, and revert this when you toggle the rendering.
     
  9. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,270
    It's because RenderMeshV2 uses BatchRendererGroup:
    from https://docs.unity3d.com/ScriptReference/Rendering.BatchRendererGroup.AddBatch.html
     
  10. SebastianAaltonen

    SebastianAaltonen

    Unity Technologies

    Joined:
    Feb 21, 2020
    Posts:
    112
    In Hybrid Renderer V2, you could use DisableRendering tag component. Just add it to every entity. This will remove them from current render batches and will prevent them from getting to render batches anymore:

    Code (CSharp):
    1. EntityManager.AddComponentData(EntityManager.UniversalQuery, new DisableRendering());
    It's slightly faster to add/remove DisableRendering to/from entities that have RenderMesh.
     
  11. spectre1989

    spectre1989

    Joined:
    Oct 6, 2009
    Posts:
    125
    I can't disable RenderMeshSystemV2 right after adding the tag, because RenderMeshSystemV2 needs to update once to process the tag!

    Ahhh, I see, thanks!

    @SebastianAaltonen I can't find the DisableRendering tag, what namespace is that in? I assume I still need to apply this tag to any entity which is created after rendering has been disabled? Is this the best way to solve this problem or is there a better way?
     
  12. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    I believe he's referring to the upcoming release(thats hopefully dropping any time now)
     
  13. SebastianAaltonen

    SebastianAaltonen

    Unity Technologies

    Joined:
    Feb 21, 2020
    Posts:
    112
    Hybrid Renderer V2 (experimental) will ship as part of Unity 2020.1. New document will have instructions how to enable it.
     
    thelebaron likes this.
  14. spectre1989

    spectre1989

    Joined:
    Oct 6, 2009
    Posts:
    125
    Awesome, thanks - and this would be the recommended way to solve this kind of issue?
     
    T-Zee and SebastianAaltonen like this.