Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

What exactly are static entities in dots?

Discussion in 'Entity Component System' started by daschatten, Nov 24, 2019.

  1. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    Does static mean:

    * only LocalToworld, but no Translation, Rotation and Scale components?
    * with Static component?
    * with FrozenRenderSceneTag component?
    * a combination of them?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    They are created by adding the EntityStaticOptimization component to the root of a hierarchy.
    This only works if you use subscenes.

    you can do it yourself using the components you describe above, but we do not recommend building entities directly out of its runtime components. Generally speaking you want to use subscenes & conversion workflow.
     
    MNNoxMortem likes this.
  3. frarf

    frarf

    Joined:
    Nov 23, 2017
    Posts:
    27
    Right. I've been meaning to ask - if we're generally not supposed to use runtime components to generate entities, what do we when should? If I have a Player component that splits MoveSpeed into Acceleration and TopSpeed in a PlayerAuthoring component, how can I use that authoring component at runtime? We can't instantiate MonoBehaviours after all.
     
  4. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    You use the conversion flow. Either create your own monobehaviour that implements
    IConvertGameObjectToEntity, or rely on the new GenerateAuthoringComponent attribute placed on the component to auto-create the authoring part.

    In general GenerateAuthoringComponent works when you have an easy 1:1 mapping of authoring behavior to component data, IConvertGameObjectToEntity when you need a bit more control (for example split 1 behavior into 2 runtime components) and you can also write a conversion system that can convert multiple objects at once (for example grouping them or writing into custom blobs and such).

    If you are not familiar with this workflow, I really recommend you watch this talk from Unite:
     
  5. frarf

    frarf

    Joined:
    Nov 23, 2017
    Posts:
    27
    Oh I'm well aware of the conversion workflow - I'm referring to using the mutations that authoring components create to the original data at runtime. If I want to create an entity at runtime, do I have to specify all component values by hand? Or could I use the authoring component somehow?
     
  6. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    I'm not sure I fully follow what you mean by the authoring components changing data at runtime? The authoring components are only used once to convert and then not at runtime, or are you referring to the live link feature?

    Do you mean you want to use the authoring components to create "prototypes" that you then instantiate/copy at runtime? For example enemies with certain values of health and such.

    That is something I've been wondering about myself and I'm not sure yet what the best answer is for that.
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    GilCat likes this.
  8. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    For procgen reasons i need to add those components manually...

    The most important optimization seems to be to add FrozenRenderSceneTag which lowers RenderMeshSystemV2 usage (in a specific test case) from 10.6 to 0.2 ms. Though if i disable entities they are still rendered. Seems there is a lot of caching involved. How can i refresh a group (grouped by FrozenRenderSceneTag) of entities? Do i have to remove FrozenRenderSceneTag and in the next frame add Disable to hide the entities?
     
  9. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Yes. You generally want to group things into related things. Eg. tile based. So you can efficiently load / unload whole tiles for example.
     
  10. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    Yep, though i can't refresh the entities with FrozenRenderSceneTag when enabling/disabling tiles. I tried:

    * Add/remove Disabled tag
    * Move to/from another world
    * Remove FrozenRenderSceneTag, wait a frame, Add Disabled
    * Add/remove Disabled tag and update FrozenRenderSceneTag to change "GetSharedComponentOrderVersion", because it seems to refresh the cache:

    Code (CSharp):
    1. if (EntityManager.GetSharedComponentOrderVersion(scene) != version)
    2.                 {
    3.                     // Debug.Log($"Removing scene:{scene:X8} batches");
    4.                     Profiler.BeginSample("Remove Subscene");
    5.                     m_SubsceneTagVersion.Remove(scene);
    6.                     m_InstancedRenderMeshBatchGroup.RemoveTag(scene);
    7.                     Profiler.EndSample();
    8.                 }
    Nothing helps. Any hint?
     
  11. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    So regarding the original topic, if I want a static entity, I need to make a mono behaviour prefab, mark it as static in the inspector, then instantiate it via the conversion workflow in my system?
     
  12. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    And how about procedural generated or data loaded from a file, that does not exist in the editor (e.g. an entity with a mesh loaded form some file at runtime)?

    If I understood it correctly the whole SubScene Conversion Workflow is centered around prefabs and gameobjects existing in the Editor.
     
    jdtec and charleshendry like this.