NPE in editor when creating SubScene

I’m migrating from 0.51 to 1.0. I’ve removed all the ConvertTo components and added the corresponding bakers, and I updated the API changes accordingly. In short, my IDE is green again and also the code generation works when switching back to Unity.

Now, with literally an empty scene, I create a new SubScene, select it, and get this in the editor:

NullReferenceException: Object reference not set to an instance of an object
Unity.Scenes.Editor.SubSceneInspectorUtility.GetLoadableScenes (Unity.Scenes.SubScene[] scenes) (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Scenes.Editor/SubSceneInspectorUtility.cs:110)
Unity.Scenes.Editor.SubSceneInspector.OnInspectorGUI () (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Scenes.Editor/SubSceneInspector.cs:343)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass71_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

So it seems that World.DefaultGameObjectInjectionWorld is null.

What did I miss?

It’s an open source game and my current branch is here in case anyone wants to have a look.

So, any idea why World.DefaultGameObjectInjectionWorld would be null in the editor? I think in 0.51, the worlds would only get created during runtime, but this seems to have changed with 0.50+, so how could my code prevent world creation during editor time?

Same problem

I have the same problem in 1.0.16 version. Just made a script that runs in edit mode, checks if World.DefaultGameObjectInjectionWorld == null and if so, creates the new world and sets this one for World.DefaultGameObjectInjectionWorld. Haven’t found any other solution yet.

using Unity.Entities;
using UnityEngine;

[ExecuteInEditMode]
public class DefaultWorldSettingManager : MonoBehaviour
{
#if UNITY_EDITOR
    private void Update()
    {
      
        if (World.DefaultGameObjectInjectionWorld == null) 
        {
            var worlds = World.All;
            World world = null;
            foreach(var currentWorld in worlds) 
            {
                if(currentWorld.Name == "Default") 
                {
                    world = currentWorld;
                    break;
                }
            }

            if(world == null) world = new World("Default");

            World.DefaultGameObjectInjectionWorld = world;
        }
    }
#endif
}