New SubScene & ConvertToEntity workflows

With the Unity.Entities release today, we are adding support for SubScenes and the new ConvertToEntity script. The main concept is that instead of using ComponentDataProxy / ComponentDataWrapper. We simply convert existing game objects or MonoBehaviours to pure entity data. This is the same workflow we used to build the MegaCity demo.

This makes it possible to create content for Unity.Entities in an effective way.

We have updated the HelloCube samples to show it:

This scene uses ConvertToEntity and shows how to create a MonoBehaviour as editing representation and then convert it to an efficient entity representation:
https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/Samples/Assets/HelloCube/2.%20IJobForEach/RotationSpeedSystem_IJobForEach.cs

https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/Samples/Assets/HelloCube/2.%20IJobForEach/RotationSpeedAuthoring_IJobForEach.cs

ConvertToEntity is great for getting started in a simple scene and see the conversion workflow doing itā€™s thing, but it doesnā€™t help with improving load times. SubScenes do. Essentially when saving the scene, we also write out a cached entity binary representation. SubScenes is what allowed the megacity to scale, since we only ever load the game object representation for editing a specific part of the world:

https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/Samples/Assets/HelloCube/4.%20SubScene

Instantiating a prefab using the same conversion flow for existing MonoBehaviour scripts is also very easy now:
https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/Samples/Assets/HelloCube/5.%20SpawnFromMonoBehaviour

https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/Samples/Assets/HelloCube/5.%20SpawnFromMonoBehaviour/Spawner_FromMonoBehaviour.cs

Best of all that same workflow can be used to convert game object references to prefab references:
https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/Samples/Assets/HelloCube/6.%20SpawnFromEntity

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

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

NOTE: This new Unity.Entities release requires 2019.1

34 Likes

Just adding a note that new Entities release doesnā€™t work on 2019.2.0a6 due to missing API there (Edit: Unity just released 2019.2.0a7. New Entities do run with it :)) New samples also run fine on 2019.1.0b4.

For Subscene samples, one has to hit the ā€œRebuild Entity Cacheā€ on the sample scenes, otherwise new samples were really straight forward (I really dig the clarity on current samples).

2 Likes

Iā€™m curious to try out this approach, especially in more complex scenarios to see how it holds up.

Iā€™ve been thinking for a while about what a PureECS ā€œprefab editorā€ could look like, and I havenā€™t yet been able to imagine something good and user-friendly (thatā€™s not to say itā€™s impossible; just that I personally couldnā€™t come up with anything yet). So I think this conversion workflow has potential

More specifically, Iā€™m thinking about what it would be like to create a very complex prefab with complex logic in it, such as an animated character with:

  • a bone hierarchy (one entity per bone, and possibly one more entity for the entire ā€œrigā€)
  • hit boxes (one entity per collider)
  • ragdoll setup (one entity per rigidbody and one more entity per collider, potentially. Maybe even one more entity per joint)
  • a skinned mesh renderer
  • a character controller capsule
  • a ā€œCharacterManagerā€ component that has references to character Bones, Meshes, Materials and other Prefabs for all sorts of purposes (in the case of Meshes, Materials and Prefabs, they cannot live on a IComponentData so that would be something to think about. And in the case of Bone references, they would be references to the specific Bone entities of that character instance). How could those ā€œreferencesā€ be edited in GameObject mode and then converted to ECS?
  • etcā€¦
7 Likes

@Joachim_Ante_1 , awesome work. Btw is that still long way to go to have pure entity editing at Scene? Will I able to edit current Game Object and entity together at the same Scene when this feature arrives?

This is good news!

1 Like

Awesome to see how ECS-in-editor crucial pieces are coming together now.

We convert whole transform hierarchies. You can have as many references to other objects as you like using Entity refs on the component data side. So all of this can be done now.

Also do note, that referenced prefabs as shown in the spawner sample support instantiated linkedentitygroup. Meaning you have full prefab workflows, where you can instantiate a whole collection of entities in one group just like Instantiate(GameObject) clones the whole sub-hierarchy and remaps any references. It makes the whole thing all of a sudden feel much more like Unity.

11 Likes

The conversion workflow is useful because it lets us convert existing content, scenes, prefabs and the output from existing tools.
It lets us have useful tooling today.

In parallel we are developing dedicated entity editing tools.

But in fact the principle there is the same. Editor and Runtime representation is different. For editing you want larger components, at runtime you want to split it out into small atomic pieces. The new entity editing tool is just much more in depth built specifically for entities. Does a better job visualizing these transformations.

11 Likes

Hi, Can I use this new subscene system for partly streamed world? in example, load subscenes which is located nearby camera only. Current subscene systems seems that load all subscenes automatically. Can I customize loading strategy?

Also, how about scene-related asset, especially lightmap. I baked lightmap with subscenes, but it disappeared when I play it. (maybe automatically converted RenderMesh does not support lightmap yet?)

Can I customize loading strategy?
Yes. Simply add the RequestSceneLoaded tag component on the scene entity, when you want to load it and conversely remove it when you want to unload. The auto-load checkbox does exactly that.

Lightmap baking is not supported yet by the DOTS renderer.

17 Likes

I hit the ā€œlikeā€ button so hard my mouse exploded.

9 Likes

Very curious to hear from anyone who has already tried it out how the new conversion flow is actually working for you?

Have no time to test it, because new release completly broke every thing :slight_smile: And I spend all time to repair (from 0.0.24 to 0.0.26 package)

I got my stuff back in working order again last night. Will take a crack at modifying it to use the new conversion tools tonight or tomorrow night.

1 Like

Yep, me too. Finally migrate and fix all from 2018.3 to 2019.1 and 0.0.24 to 0.0.26

So Iā€™ve been using scene conversion since p22 or whenever it was added. With p26 Iā€™ve converted this over to new sub scenes (which only took minutes) so it hasnā€™t been a huge change in my workflow.

Anyway hereā€™s a few notes, using Unity: 2019.1b5, in no particular order.

  1. Keep getting a UI elements / serialization exception if I have the SubScene script selected when playing a scene.
ArgumentException: Object at index 0 is null
UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs, UnityEngine.Object context) (at C:/buildslave/unity/build/Editor/Mono/SerializedObject.bindings.cs:39)
UnityEditor.Editor.GetSerializedObjectInternal () (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:545)
UnityEditor.Editor.get_serializedObject () (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:452)
UnityEditor.UIElements.InspectorElement..ctor (UnityEditor.Editor editor, UnityEditor.UIElements.InspectorElement+Mode mode) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:133)
UnityEditor.UIElements.EditorElement.Init () (at C:/buildslave/unity/build/Editor/Mono/Inspector/EditorElement.cs:47)
UnityEditor.UIElements.EditorElement..ctor (System.Int32 editorIndex, UnityEditor.InspectorWindow iw) (at C:/buildslave/unity/build/Editor/Mono/Inspector/EditorElement.cs:31)
UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1358)
UnityEditor.InspectorWindow.RebuildContentsContainers () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:613)
UnityEditor.InspectorWindow.RedrawFromNative () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:293)

Seems harmless just annoying as it trips ā€˜error pauseā€™ entering play mode.

  1. Is there an automated way to handle lights (or other non convertible game object components) that Iā€™ve missed?

I currently use a custom game object conversion system
public class LightConversion : GameObjectConversionSystem
and a custom System that initializes them.
https://gist.github.com/tertle/5eb0084404a8dc69616ed37699b0fd23

  1. TransformConversion has caused me a few issues.

It adds a Translation/Rotation proxy to entities which is an issue if your entity already has the proxy!

Previously I had a few GameObjectEntity prefabs that I had both in scene and I also used at runtime. This means I either had to remove the proxies when I put the object in a scene, or add the proxies when I initialized them at runtime.
Instead I just overrode the TransformConversion with a custom version that did a check before adding the component.

https://gist.github.com/tertle/b70563c21e12452038aa14805d7f3d87

This is based off the previous version of TransformConversion (p24) and I know itā€™s been updated in p26 but Iā€™ve stopped using it so itā€™s just legacy pulled from repo.

Instead of doing this now though, Iā€™ve decided to ditch ComponentDataProxies completely and just rely on IConvertGameObjectToEntity, so this isnā€™t an issue for me anymore but others might run into it.

  1. Overall, pretty happy with the system, it plugs in nicely to my preferred workflow. Iā€™m pretty sure I had some other feedback when I was converting yesterday but Iā€™ve just woken up and forgotten. Iā€™ll post more as I remember.

It adds a Translation/Rotation proxy to entities which is an issue if your entity already has the proxy!
The idea is that we want everyone to stop using ComponentDataProxy completely. We havenā€™t deprecated it yet. But i think it fundamentally doesnā€™t fit the conversion flow conceptā€¦

2 Likes

Well thatā€™s good because I decided to stop using them after this update and converted them to IConvertGameObjectToEntity MonoBehaviours instead. Is that the recommended workflow?

1 Like

Yes.

4 Likes

Thatā€™s a really good call. The current HybridECS workflow involving GameObjectEntity and ComponentDataProxy has too much coupling between GameObjects and Entities, and frankly too much performance bog in the OnEnable & OnDisable.

Thinking those will be replaced sooner or later, I also converted everything to be using IConvertGameObjectToEntity yesterday and today (effectively getting rid of all GameObjectEntity and managing GO-to-entity relations on my own). Now thereā€™s much better separation between GOs and entities. Using the entity spawner pattern also feels really good and natural. In general, very happy with this release.

3 Likes