[SOLVED] Change scene by scene id in build

Hey guys, I want to change scenes while playing, by this code it’s working on editor link but in the publish link it’s not working:

here is the error from console log of Chrome:
https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/5c5e88d3/1969950 403 (Forbidden)

Hi @abouzarp and welcome!

The changeScene API works with scene names.

this.app.scenes.changeScene('Some Scene Name');

Is there a reason why you don’t use the scene name?


Actually in Unity you can load a scene base on build id and it’s very handy cause maybe u change the scene name while in the producion and u need to change it in code too.
PlayCanvas scene id is working in the editor link but not in the publish link

Alright, I personally don’t know if there is a way to use the scene ID. You can find all scenes of the project using SceneRegistry.

const sceneItems = this.app.scenes;
for (let i = 0; i < sceneItems.length; ++i) {
1 Like

You can only change by a scene name, scene item or path:

// by name

// by item
const item = app.scenes.find('my-scene');          // option 1
const item = app.scenes.findByUrl('1969950.json'); // option 2
if (item) {

// by path

You are probably looking for the path variant. Calling changeScene will create a new scene, if it cannot find it.


thanks a lot, by path is working for me, here is the tested script on publish link: