Toggling Rendering For An Entire World

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:

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?

I think disabling RenderMeshSystemV2 should work.

I tried this

this.World.GetExistingSystem<Unity.Rendering.RenderMeshSystemV2>().Enabled = false;

no dice :frowning:

Is GPU instancing enabled on your materials? I suspect they might be causing it.

No, I’m just creating some basic primitives which all use the built in material “Default-Material”

Adding FrozenRenderSceneTag without specifying the SceneGUID does it for me.

EntityManager.AddSharedComponentData(EntityManager.UniversalQuery, new FrozenRenderSceneTag());

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.

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.

It’s because RenderMeshV2 uses BatchRendererGroup:

[quote]
Each batch corresponds to a new draw call. As long as the batch is not removed and the group is not disposed of, the command is persistent and doesn’t need to be called every frame. Returns the batch’s index within the group.
[/quote] from https://docs.unity3d.com/ScriptReference/Rendering.BatchRendererGroup.AddBatch.html

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:

EntityManager.AddComponentData(EntityManager.UniversalQuery, new DisableRendering());

It’s slightly faster to add/remove DisableRendering to/from entities that have RenderMesh.

4 Likes

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?

I believe he’s referring to the upcoming release(thats hopefully dropping any time now)

Hybrid Renderer V2 (experimental) will ship as part of Unity 2020.1. New document will have instructions how to enable it.

1 Like

Awesome, thanks - and this would be the recommended way to solve this kind of issue?

2 Likes