Examples of using DOTS ECS 1.0 with UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP_RUNTIME_WORLD

Hi,

I find the new DOTS 1.0 ECS documentation somehow cleaner and simpler, but it lacks any indication about how to use it with UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP_RUNTIME_WORLD (or even UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP if this doesn’t cause troubles with the new DOTS)

now that GameObjectConversionUtility.ConvertGameObjectHierarchy is gone I am not really sure about how to create entities from unity prefabs without needing a subscene.

My only guess at the moment is that I have to add the baking systems in my custom world and use a subscene anyway? Examples of how to replace ConvertGameObjectHierarchy with UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP and custom worlds are appreciated.

For my case, it’s important that I can access the Entity value from outside a system, specifically in the composition root. I understand that it’s quite a specific case, so I will not be surprised if there isn’t a way to do this anymore.

Edit: I think I would be able to solve my problem if I understand how to use the new Baking system with a custom world newed via code at runtime.

For baking it makes sense to always have a default world. Even if all it does is store prefabs. That is what I do. I still have custom worlds.

You can still disable the default system generation. That is what you are referring to if I’m not mistaken. Here are some links to those pages in the documents:

World concepts - World concepts | Entities | 1.0.16
System concepts - System concepts | Entities | 1.0.16

It sounds like the baking system is what you are going to have to use. They replaced the other conversion system (which was much more straight-forward) with the new “Baker” approach… Not my favorite change in ECS 1.0

You cannot just slap the conversion component on a prefab anymore, and let it do the conversion. You will need to set up the “Baker” converter, and it will convert the prefab into an entity. Here is some more information on how Baking works - Baking | Entities | 1.0.16

Hope some of this helps… You may be on the right track with needing to use a special sub-scene, but you should be able to use a special world instead if necessary.

Hey thanks! If I use the default system to bake, I think the entity will be found in the default world and won’t be processed by the custom world. I may be able to copy entities from the default to the custom world perhaps. I would need more details @TheOtherMonarch .

Use some kind of query get a NativeArray of your prefabs and use CopyEntitiesFrom.

Thanks, I will defo try this, but I suspect there must be a way to load subscenes in custom worlds.

OK something like this without using a default world (thus with UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP ) is working somehow

var sceneEntity = SceneSystem.LoadSceneAsync(
                customWorld.Unmanaged,
                new EntitySceneReference(
SceneSystem.GetSceneGUID(ref customWorld.Unmanaged.GetExistingSystemState<SceneSystem>(), "Assets/Scene/CombiningBehaviours/Prefabs.unity"),
0));

            while (SceneSystem.IsSceneLoaded(customWorld.Unmanaged, sceneEntity)
                == false)
            {
                customWorld.Update();
                await Task.Yield();
            }

var worldEntityManager = customWorld.EntityManager

var query = worldEntityManager.CreateEntityQuery(typeof(PrefabsHolders.MyComponent));

var prefabHolder = query.ToComponentDataArray<PrefabsHolders.MyComponent>(Allocator.Temp);

var component = prefabHolder[0];

var redFoodPrefab = component.RedFood;
var blueFoodPrefab = component.BlueFood;
var redDoofusPrefab = component.RedDoofus;
var blueDoofusPrefab = component.BlueDoofus;
var specialBlueDoofusPrefab = component.SpecialDoofus;

with

public class PrefabsHolder: MonoBehaviour
{
    public GameObject BlueDoofus;
    public GameObject RedDoofus;
    public GameObject SpecialDoofus;
    public GameObject RedFood;
    public GameObject BlueFood;
 
    public class MyBaker: Baker<PrefabsHolder>
    {
        public override void Bake(PrefabsHolder authoring)
        {
            AddComponent(new MyComponent
            {
                    BlueDoofus = GetEntity(authoring.BlueDoofus),
                    RedDoofus = GetEntity(authoring.RedDoofus),
                    SpecialDoofus = GetEntity(authoring.SpecialDoofus),
                    RedFood = GetEntity(authoring.RedFood),
                    BlueFood = GetEntity(authoring.BlueFood),
            } );
        }
    }
 
    public struct MyComponent : IComponentData
    {
        public Entity BlueDoofus;
        public Entity RedDoofus;
        public Entity SpecialDoofus;
        public Entity RedFood;
        public Entity BlueFood;
    }
}

let me know if this can be improved or if there could be problems with it, please. The only problem I seem to have at the moment is exceptions during the dispose of the custom world.

edit: it seems to not work in a built client

edit2: it did work if I use the hash value directly, but the subscene must be in the main scene, otherwise I guess the scene won’t be bundled with the client.

edit3: it works only in a mono client, it fails in a IL2CPP client

Hello @sebas771 , did you look at Weakly reference a scene | Entities | 1.0.16 ?

It could be easier, but i’m not sure if it was already available in january. I’m thinking of using with Baker and Blob Asset Create a blob asset | Entities | 1.0.16 ( bottom of the page )

I’m trying to use UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP but I did not got far yet, I’m not sure to understand if I basically have to redo everything that is done in the default BootstrapWorld script