What exactly are static entities in dots?

Does static mean:

  • only LocalToworld, but no Translation, Rotation and Scale components?
  • with Static component?
  • with FrozenRenderSceneTag component?
  • a combination of them?

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.

1 Like

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.

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:

https://www.youtube.com/watch?v=BNMrevfB6Q0

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?

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.

prefabs are supported just fine in conversion flow.

https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/ECSSamples/Assets/HelloCube/5.%20SpawnFromEntity/SpawnerAuthoring_FromEntity.cs

https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/ECSSamples/Assets/HelloCube/5.%20SpawnFromEntity/SpawnerSystem_FromEntity.cs

Note:
To simplify the whole thing you can use [GenerateAuthoringComponent] on the IComponentData. For any Entity fields on the icomponentdata it will create a game object reference on the authoring component.

1 Like

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?

Yes. You generally want to group things into related things. Eg. tile based. So you can efficiently load / unload whole tiles for example.

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:
if (EntityManager.GetSharedComponentOrderVersion(scene) != version)
                {
                    // Debug.Log($"Removing scene:{scene:X8} batches");
                    Profiler.BeginSample("Remove Subscene");
                    m_SubsceneTagVersion.Remove(scene);
                    m_InstancedRenderMeshBatchGroup.RemoveTag(scene);
                    Profiler.EndSample();
                }

Nothing helps. Any hint?

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?

1 Like

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.

2 Likes