Export only objects used for current scene?

Is it possible to export a project so only the assets used in the exported scenes are exported?
It seems like PlayCanvas exports every single file in the project.

The “Exclude” flag seems to work to exclude assets from being used in the build, but unfortunately that’s not really a viable solution if we need to set the “Exclude” flags again every time we export a different scene.

Different projects are not a viable solution either because it makes code maintenance hard, as we’d have to update every project manually.

Hi @DJ_Coco,

No there isn’t a system to do that right now. You will have to do this manually e.g. using the Editor API to filter and tag the required assets accordingly.

Simplest way is by using tags, more advanced ways would be to try and find component references. And of course make sure that your scripts aren’t accessing an asset directly since that reference will not show in editor.

In PlayCanvas, scenes don’t have any direct relationship with the assets so it’s not possible to know what is being used in the scene. It’s also possible to load assets dynamically in code which makes it pretty much impossible to reliable find all assets used in a scene.

In this scenario where you have one uber project and each scene is effectively a separate project, I’ve generally suggested the following options:

  1. Instead of a project per scene, switch to a project per branch were the main branch is the core shared libraries. This way changes to the core can be upstreamed to the branches and each branch can have only the assets and scenes it needs. I talk more about it here: Selective merge of branches · Issue #654 · playcanvas/editor · GitHub If you do go down this route, I would HIGHLY encourage backing up each branch via the REST API with the branch ID on a regular basis (there’s a tool here that can make this easier). Forking will only make a copy of the main branch.

  2. Tag assets with the scene id or some other identifier that you use. Eg ‘shared’ for assets used across all scenes and ‘scene 1’/‘scene 2’ etc for other assets. Then use a post build processing script that takes a self hosted build zip, looks through config.json (that stores the asset registry) and deletes the asset files and the asset entry in the JSON that you don’t need via the tags based on the scene that is being exported. (Redox custom cloud build tool may be able to help you with this https://playcanvas.redox-interactive.com/)

  3. Do similar to 2. with the tagging but instead deleting files and using the standard preloader, have a custom loading script in the project that will only load the assets needed for the scene that is being loader. Your overall build size is still quite large as a zip but the user only downloads assets that are needed for the scene that is being loaded

1 Like