More control needed in app startup in editor project

I would like more control of the app startup sequence in editor projects so that I can:

  1. ignore the editor asset preload feature and implement my own asset preloader.
  2. modify the scene entity hierarchy before it starts rendering, and also before other needed assets are loaded.

I can actually do this by utilising the fact that a custom loading screen callback is called before the preloading and scene loading. But it us a bit clunky, especially point 2 above where I have disable the scene root entity in the editor and then enable it later programatically.

Is there a better way? Could the engine provide a new api to give more control?

Here is a test project and code. You’ll see a blank screen because the root entity is disabled but when you run it press any key to enable it. If you enable dev tools you can see that the assets are loaded after the “start” event is fired, rather than before.

It’s unlikely that this would be done in the near term.

What developers tend to do is have their first scene be the preloader.

This means have nothing ticked as preload or have the bear minimum to have to loading a barebones loading scene, the game boots into a scene that will load what is needed and load into the actual game

This saves on the clunkiness of what you’ve mentioned above?

Thanks for the reply. I’m not sure having an empty scene to start from will help me. I’ve probably got an unusual use case.

  • I’m looking to automatically disable asset preloading rather than manually disabling in the asset inspector. So I’d still need to do that.
  • Let’s say I always start from an empty scene1. If I then want to load the hierarchy in scene 2 but I want to modify it before it starts rendering and before it starts loading assets, then I will have the same problem. I think I would need to disable the root entity in scene 2 and then enable it in code and that is the clunky part. When I want to edit the scene in the editor I need to enable the root entity and when I want to run the scene I need to remember to disable the root entity.

The other thing that would be very useful would be an api to provide a list of the asset ids for assets required by an entity hierarchy, whether that is a whole scene or just part of scene. This could be used when loading and unloading assets required by an entity hierarchy.

It seems that I might have achieved what I wanted by starting from an empty scene and also utilising loadSceneData(sceneItem, callback) to disable the Root entity in the target scene data before the hierarchy is created, and then re-enabling Root after the hierarchy is created.

You can use the Editor API to go through all the assets and disable preload. You can also tick this option so that any new uploaded asset doesn’t get marked as preload.

What do you mean by ‘modify’? Are you removing, adding entities etc?

I would be more tempted to use templates or sub scenes and build up a ‘scene’ than modify one

For the preloading part I thought of looking at the Editor API too, I will check that out.

For the modify part I am thinking of just enabling/disabling. I haven’t tried in anger yet, but the scenario I was thinking was this. Imagine I have an entity house and children of that are house-lod1, house-lod2, house-lod3, or house-mobile. In the editor I want to be able to interact with the children entities eg setting them up, enabling and disabling as I work on each, but at runtime I want to choose in code which one to display. However when the scene hierarchy is created the assets that haven’t been preloaded are automatically loaded if enabled and referenced in the scene. I want to prevent this automatic loading of assets until I have enabled the correct entity. I have achieved this by disabling entities after the scene data is loaded and then loading the scene. The code linked above does seem to work though.

1 Like