I would like more control of the app startup sequence in editor projects so that I can:
ignore the editor asset preload feature and implement my own asset preloader.
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.
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.
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.