Search Unity

staticChunksOrderVersion not updated when moving entites from non active world?

Discussion in 'Entity Component System' started by Bas-Smit, Oct 9, 2019.

  1. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    I am trying to instantiate entities in streaming world (ie not World.active), bring them over to the active world, and have them rendered statically. The steps Im taking are:

    Convert gameobject prefabs:
    Code (CSharp):
    1. var s = new GameObjectConversionSettings(w,  GameObjectConversionUtility.ConversionFlags.ForceStaticOptimization);
    2. GameObjectConversionUtility.ConvertGameObjectHierarchy(p, s);
    Instantiate entities and assign FrozenRenderSceneTag:
    Code (CSharp):
    1. EntityTransaction.Instantiate(p);
    2. EntityTransaction.SetSharedComponentData(e, new FrozenRenderSceneTag { SceneGUID = new Hash128 {Value = id} });
    Optimize:
    Code (CSharp):
    1. EntitySceneOptimization.Optimize(w);
    Move entities to active world:
    Code (CSharp):
    1. EntityManager.MoveEntitiesFrom(em, query, remap);
    The problem is that RenderMeshSystemV2 fails to update the frozen render batches, it returns here:
    Code (CSharp):
    1. void UpdateFrozenRenderBatches()
    2. {
    3.     var staticChunksOrderVersion = EntityManager.GetComponentOrderVersion<FrozenRenderSceneTag>();
    4.     if (staticChunksOrderVersion == m_LastFrozenChunksOrderVersion)
    5.         return;
    6.     ...
    7. }
    8.  
    If I create an entity with a FrozenRenderSceneTag in the active world RenderMeshSystemV2 updates the frozen batches and things are rendered as expected:
    Code (CSharp):
    1. EntityManager.SetSharedComponentData(e, new FrozenRenderSceneTag{SceneGUID = new Hash128{Value = new uint4(1,2,3,0)}});
    Is there a better way of getting RenderMeshSystemV2 to update its batches, or is this a bug?

    Thanks, Bas
     
    esc_marcin likes this.