Avoiding RenderMeshSystemV2.UpdateDynamicRenderBatches for static entities?

I convert a bunch of gameobject prefabs that I then instantiate and they render as expected. Looking at the profiler most of RenderMeshSystemV2’s time is spent in UpdateDynamicRenderBatches. At the moment I only have static entities though, so it feels like I should be able to skip this computation. I tried adding the Static to all entities, but this seems to have no effect. Is it already possible to render static entities more efficiently?

Thanks, Bas

May need to play around with FrozenSceneRenderTag. Refer to this thread: ANCIENT THREAD! - Hybrid Renderer Sandbox

relevant msg

example

using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;
using Unity.Transforms;
using UnityEngine;
using Hash128 = Unity.Entities.Hash128;

public class StaticTest : MonoBehaviour
{
    public GameObject Prefab;
    static EntityQuery _noRenderSceneTagQuery;

    void Start()
    {
        var em = World.Active.EntityManager;

        _noRenderSceneTagQuery = em.CreateEntityQuery(new EntityQueryDesc
        {
            All = new[] {ComponentType.ReadOnly<RenderMesh>()},
            None = new[] {ComponentType.ReadOnly<FrozenRenderSceneTag>()}
        });

        var s = new GameObjectConversionSettings(World.Active, GameObjectConversionUtility.ConversionFlags.ForceStaticOptimization);
        var e = GameObjectConversionUtility.ConvertGameObjectHierarchy(Prefab, s);
    
        var id = new uint4(1, 0, 0, 0);
        InstantiatePrefab(e, em, new LocalToWorld {Value = float4x4.TRS(new float3(0, 0, 0), quaternion.identity, 1)}, id);
        InstantiatePrefab(e, em, new LocalToWorld {Value = float4x4.TRS(new float3(10, 0, 0), quaternion.identity, 1)}, id);
    }

    static void InstantiatePrefab(Entity e, EntityManager em, LocalToWorld localToWorld, uint4 id)
    {
        var instance = em.Instantiate(e);
        foreach (var entity in em.GetBuffer<LinkedEntityGroup>(instance))
            em.SetComponentData(entity.Value, localToWorld);

        em.AddSharedComponentData(_noRenderSceneTagQuery, new FrozenRenderSceneTag
        {
            SceneGUID = new Hash128 {Value = id}
        });
    }
}

make sure your entities show up here when RenderMeshSystemV2 is selected:

6 Likes