Our team is working on a game of which the ui is kind of complicated and takes more than 1500 entities.
When run on a modern smart phone (4GB RAM, snapdragon 660), it takes 2 seconds to create the scene, and more than 7 seconds on an older phone (presented in 2014, 3GB RAM, snapdragon 801).
Any suggestion about how to speed this up would be well appreciated.
I would start with benchmarking first to see where the bottle necks are.
Are they from network loads?
Logic being performed in the initialize functions?
Simply from having 1500 empty entities?
Other ideas include staging the initialisation of the scene over several frames. Do they all need to be active/there at the start? Can you use some form of spatial partitions to load areas of the scene only when they are in use/visible?
Edit: just read it’s just purely from the UI. 1500 sounds a lot and I can’t imagine any UI that needs that many. (Nor have I come across one that requires that many)
Like I mentioned above, does it all need to be created at once at the beginning? Is it all shown at once? Can you create it over several frames? Where’s the bottles necks shown in the profiler? Can the number of entities used be reduced in the UI?
The UI is created with the online playcanvas editor then exported to a web bundle. This produces a config.json and one json file per scene. During run time, the scene is loaded with pc.Application.loadSceneHierarchy.
You can split the UI into multiple scenes and load them additively over a series of frames to reduce the initial load. That would be the bandaid solution.
Beyond that, 1500 entities just sounds insane for a UI without context of what it is.
Edit: I assume that 1500 is for several UI screens worth? In which case, I would split up the screens (or groups of screens) into separate scenes and load them only when needed to balance out the load.
you are right, this is the home scene for our game. so we added all pop-up window (might be used more than once) to the home scene. this used to be done with prefab in other game engine.
this is our very first project, we have been working on this for more than one year. due to lack of experience, we didn’t notice it until now, it became a bottleneck of our game.
not sure how you guys deal with prefab-like features. maybe “loadSceneHeirarchy” could have a “preload” feature too? so it could load invisible entities in the background? that might involves script binding though.
and after some research, we found based on the project size, splitting the UI now involves tremendous work and uncertainty. we sincerely hope there is some ways to load entities in a non-blocking way…
The closest you can get to prefabs in PlayCanvas is to use the clone function on entities. Typically, the pattern is to have a disabled entity (e.g an item entry) and clone it when needed and return it to a pool instead of destroying it.
I can’t think of any other way to do this without splitting it into scenes as PlayCanvas is single threaded.
You might be able to patch the engine and add an asynchronous load hierarchy function using a webworker so at least you can have an animated loading scene?
Might be worth just deleting all the hidden UI elements (in a forked project) and see if that makes any significant different to the load. This should give some information on how far down the rabbit hole you will need to go.
Although we can create entities and components in several frames, the scripts must be initialised after all other work done. Because scripts depends on entities and other components to work correctly.
So the best result we can get is something like a progeess bar during scene creation.
That’s what I’m envisioning, yes. The initialize and postInitalize are most likely to have to be done on a single frame but the creation of the entities should be doable over several. I had a crack at it last night but got stuck with the editor only code of loading scenes. If I get time, I will have another shot at it later.