How to export Template from the Editor and load Template(Prefab) in my non-editor project

I built some Templates (Prefab) with scripts and models in the editor. I now want to load and display it through scripts in a web page that I write myself.
First of all, the first question is how can I export this Template. It seems that Template assets cannot be exported via download context menu in the editor。
The method I’m currently using is to publish project with some files in the editor, take out the Assets part of the Config.json, and put it in my code with app.configure(“config.json”, onOKCallback);
to load assets, but it seems that the js file will not be loaded in. The script does not work.
Is there any good process for achieving this?

If you untick preload on the template, it will be a separate JSON when published.

You will also need to make sure that all the assets the template uses (models, materials, scripts etc) are also copied over with the same asset ids. These would also need to be registered first into the asset registry before the template asset is loaded and instantiated.

Thanks for your answer, I want to confirm further, is the way for regist into the asset registry to use the app.configure() function? The config.json read by this function seems to have done something else, not specifically.
My requirement is that each template is pluggable, and I don’t want to manually edit the global config.json every time to register with assetrestry, because it’s a collaborative way of working with multiple people. Or maybe I build multiple json files and call the app.configure() function once when I load each template. Is this method desirable?

You don’t have to. You can create assets in JS and add them directly to the registry.
https://developer.playcanvas.com/en/api/pc.AssetRegistry.html#add

That way you can set the asset id directly. You could also develop your own system that loads the information from a file/files and adds them to registry before the template is used/app is started

This is pretty much what app.configure does anyway under the hood

Thinking about it, the hiccup is that some assets might not be separate JS files when you publish even with preload disabled (like materials? I can’t remember)

If that’s the case, you could write a tool that downloads the build extracts them as separate JSON files.

Rereading the original post:

The easiest thing to do here is to untick concatenate scripts when publishing. This keeps the script as a separate JS file in the assets folder under it’s asset id and you can load it like you do with any other asset.


The way I would go about it myself would to create my own asset registry configure function. After getting the necessary assets from the Editor project and adding it to an engine only project, I would have a script that goes over the engine only assets folder where all assets are and create a JSON that contains the following per asset:

  • asset id
  • asset name
  • filepath
  • asst type

That information can be extracted from the config.json file from the Editor project or I would copy the JSON from the config.json of the asset and place it as a separate JSON file in the engine assets folder on a per asset level

My generated file can then be loaded to create and add assets to the asset registry at run time

Does that make sense?

Thank you very much for the detailed answers. My doubts have been answered.
I referred to the engine code you provided, and I found that javascript assets need to be defined in scriptsOrder before they can be loaded. When I used it before, I didn’t define this variable, which caused the js to fail to load.
At present, the registration logic of asset is not very complicated, and I can use the engine code to refer to it and define my own registration function.

Also, I have a suggestion. If Editor can export templates to files, or in a unity-like unitypackage way, it is convenient to export all related files together. The program can be loaded and instantiated as needed during the run phase. Because of many complex effects, it is more convenient to edit with editors. For example, the superposition of a set of models and particles and so on.
However, when used, the non-editor environment may be more flexible, so it may be better to consider the combination of the two.

I’m afraid it doesn’t, not in a self contained way that can be loaded easily. It would need a major change to the way we do asset registries and the publish pipeline.

Copying from one project to another in the Editor is very easy but having it out of Editor to a Engine only project is difficult due to all the asset id referencing :thinking:

Oh, that useful to know!