New SubScene & ConvertToEntity workflows

how about the subscene work with asset bundle. I see the cache data is store in resource folder.

1 Like

Next step for us is to make the entity cache not be in assets folder but just be a cache like any other asset imports. We will build that on top of addressables. Ultimately we want the entity cache to be creatable by the new asset pipeline in another process with a async non-interrupting workflow.

Letā€™s call whats there right now a ā€œghetto pipelineā€, it will get a lot of love in the coming months. It was the simplest way to move it forward step by step unlocking value with a simple solution right now.

9 Likes

Right now all the conversion methods will include Translation and Rotation in the resulting entity prefab. However, one of the advantages of using entity prefabs should be the ability to exclude transform data. Will this be supported in future APIs? Either through new conversion options or the aforementioned ā€œdedicated entity editing toolsā€?

2 Likes

How can I have existing monobehaviours or components (eg BoxCollider) on a prefab that I pass into
GameObjectConversionUtility.ConvertGameObjectHierarchy

Iā€™m guessing I should create my own component to represent the BoxCollider and add that to the entity with
IConvertGameObjectToEntity, then use a system to create a gameobject and put a box collider on it then attach it to the entity with EntityManager.AddComponentObject()

I tried using EntityManager.AddComponentObject in IConvertGameObjectToEntity but it didnā€™t work, Note Iā€™m trying this with a prefab into GameObjectConversionUtility.ConvertGameObjectHierarchy then EntityManager.
Instantiate to make copies of it. Is that the wrong flow?

Hereā€™s an example I just happened to see. You have to implement the Convert method in the IConvertGameObjectToEntity and then looks like you do AddComponentData instead of AddComponentObject.

https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/Samples/Assets/HelloECS/HelloCube_02_IJobProcessComponentData/RotationSpeedProxy.cs

@Joachim_Ante_1 - adding to @Singtaa 's question, will there be (or is there already a timetable for) something like a ConvertScriptableObjectToEntity pipeline?

2 Likes

Please add abstraction layer for handling asset pipeline, not directly using addressables. Current addressables are lack of many important features like error handling, runtime re-initialization, encryption and so on. I think that making users can use their own asset management system will be more good way.

1 Like

That really sounds more like feature request for addressables themselves.

Me too, most game project has it own asset management system and it may not suitable for switching to addressable system.

1 Like

Whatā€™s the end product of this? You want any arbitrary ScriptableObject asset file in Project folder/connected in the scene to become 1 Entity with 1 component object leading to that file?

Yeah also, I donā€™t think you need a hierarchical conversion tool for ScriptableObjects becauseā€¦ they donā€™t have a hierarchy. =D

But SOā€™s-to-entity workflow is very powerful. And you can already do it today. If you serialize out your CompDatas (via Odin for example), you can create entities from SOā€™s very easily:

using Sirenix.OdinInspector;
using Unity.Entities;
using UnityEngine;
using System.Linq;
using System.Reflection;

[CreateAssetMenu(menuName = "ECS/SOEntityPrefab")]
public class SOEntityPrefab : SerializedScriptableObject {

    [SerializeField] IComponentData[] componentDatas;

    MethodInfo SetComponentDataMethod = typeof(EntityManager).GetMethod("SetComponentData", BindingFlags.Instance | BindingFlags.Public);

    [Button(ButtonSizes.Gigantic)]
    void CreateEntity() {
        var em = World.Active.GetOrCreateManager<EntityManager>();
        var entity = em.CreateEntity(componentDatas.Select(c => new ComponentType(c.GetType())).ToArray());
        foreach (var cd in componentDatas) {
            var genericMethod = SetComponentDataMethod.MakeGenericMethod(cd.GetType());
            genericMethod.Invoke(em, new object[] { entity, cd });
        }
    }

}

This sample is more for editor/playmode testing. But you can easily create entity prefab for runtime usage as well.

9 Likes

More for the ā€œsingle consistent wayā€ of an interface + supporting functions, otherwise weā€™ll all wind up hand rolling a solution.

1 Like

Since there is a way to save a group of entities to an asset (which is what subscenes are using right?) could we build a ā€œscriptable objectā€ on top of that? Even convert SO->entities asset file->then expose as a singleton.

You can add the StaticEntityOptimization component at the root of a hierarchy to get rid of it. We use that for all buildings in the megacity. Its a super important optimization. It kills off the whole hierarchy at bake time.

9 Likes

You can use GameObjectConversionSystem for this purpose. Check out TransformConversion or
MeshRendererConversion for example code.

the conversion happens at a scene level and you can pull in any data you like. For example you could read the scriptable object data and turn it into ComponentData or DynamicBuffer on an entity.

Next release will also have blob assets which is made for sharable immutable resource data. In that case, you could convert a ScriptableObject into a BlobAsset and then share it from multiple instances in the same scene.

BlobAssets are made for zero cost deserialization for large amounts of data. AnimationClip, CollisionMesh, CurveData is a good example of what we think belongs into a BlobAsset.

10 Likes

This is a really good overview
http://68.183.97.180/gameobject-conversion-ecosystem-code-tour/

Thank @5argon

6 Likes

Itā€™s fine for transform system optimisations, but itā€™s only adds Static component to entity in GameObjectConversionMappingSystem, but for example if we use our GO representation for some thing like - data storage after conversion to entity, which not require TRS, and this components just waste space inside chunk and memory itself (of course itā€™s not so huge, butā€¦) :slight_smile: I mean idea of just pure data storage entity without any representations itā€™s possible in future for conversion tool?
BTW I found time to test conversion tools and they really cool, I swich all my hardcoded archetypes and own conversion tool for prefabs to built-in conversion tool.

1 Like

Oohhh that is interesting! I guess this data is blittable or at least usable from jobs? Going to be super handy when passing data to jobs :slight_smile: thanks!

Alsoā€¦ strings are immutableā€¦ soā€¦ store strings as blobs? :slight_smile:

1 Like

There is an optimization pipeline and it removes the hierarchy and does a bunch of other data optimization for static entities.

2 Likes