Create Scenes asynchronoous

Is there any way to create new (large) scenes asynchronous / in background thread and keep a loading screen animated while doing so?

I guess this will not work easily, due to the autorelease-pool, right?

1 Like

I believe all cocos objects need to be created on the main thread but theoretically you could load all the data in a background thread and then create cocos objects on the main thread when the data is ready. I don’t know how well this would work, but I don’t think there are many other solutions.

I sis experiment with it a while ago, but the animations on the loading screen were choppy because whenever a resource was loaded, I would use the main thread to turn it into an object, which would block the animation for a moment and did so often enough to be noticeable. (I guess you could try waiting until everything is loaded before making cocos objects, but then your animations might freeze completely for a little while.)

If you just want a loading bar, you can fake it by loading a resource, updating the progress bar when it’s loaded and then scheduling the next resource for a frame later (I think).