[SOLVED] Why playcanvas loads so much unneeded assets?

I am facing an issue with PC in terms of build system & loading assets.

I am using an organization plan and I am creating project with number of assets. I’ve stumbled across strange thing when I start to investigate why it is loading so slow (i mean loading time on initialization, something seemed wrong). In this project I have several scenes that are standalone, but share whole bunch of scripts. So I thought that it will be good idea to organize all of them in a one project, and then separate them into scenes inside PC. But then I’ve realized that PC seems to be loading assets even if they doesn’t appear in the scene(s) bundled in build! Event more - I’ve tried to create an empty scene and then create build containing only this empty scene and then checked amount of data downloaded while initializing and the result was: all assets from other scenes (models, textures, etc.) started to show up in a network panel in chrome dev tools (houndred of megabytes downloaded with build with single empty scene included) .

I am wondering if there is something I am doing wrong or it is just the way the play canvas works? Please tell me, that I don’t have to create a new project for individual scene and copy scripts (it would be pain in the ass to maintain scripts that way).

I would really appreciate any help.

Every asset has a ‘preload’ toggle. If this is ticked, this asset is loaded at the initial download of the app.

When it is toggled off, it doesn’t get loaded at the start and is only loaded when it is needed (either by dependency or directly). Or you can load the asset via code (for example, at the start of a level, when a button on the UI is clicked etc) so it is ready ahead of time.

This page explains it better: https://developer.playcanvas.com/en/user-manual/assets/preloading-and-streaming/

There are also a few sample projects in the tutorials section. https://developer.playcanvas.com/en/tutorials/?tags=assets

well, I must say that i’ve noticed ‘preload’ toggle before but it didn’t cross my mind that it will be the only thing. Can someone explain what difference makes including/excluding particular scenes from the build?

It includes/excludes the scene layout from the build (ie. It can’t be accessed) otherwise there will be a JSON file in the build/publish folder somewhere that contains that scene data.

The asset registry is global to the engine.

Okay, thank you so much for clarification. I can’t say that I am happy with it, but at least I know how to move on :slight_smile: Again, thx.

To put it another way, there is nothing in PlayCanvas that works out what assets you are using/not using so the build of the project will literally include everything you have in the project (barring the scenes that are defined in the build window (I think this was done this way because team members may have ‘sandbox’ scenes where they are quickly trying stuff out, working on something small and are not for production)).

The only way to control what gets loaded at the start of the app load is the ‘preload’ toggle.

Good luck!