☑ Can't switch scenes

var Startgame = pc.createScript('startgame');

Startgame.prototype.initialize = function() {
    this.entity.script.sprite.on('click', this.onClick, this);
};

Startgame.prototype.onClick = function() {
    app.rootnew.destroy();

     
        app.loadSceneHierarchy("458124.json", function (err, parent) {
            if( err ){
                console.log(err);
            }else{
                console.log("no erros loading level");
            }
        });
};

Why don’t you just enable/disable entities within a scene rather than using separate scenes? I think you’re over-complicating things.

So in the hierarchy you could do:

Root
|— UI
|— Level 1
|— Level 2
|— Level 3

And code would be:

var Startgame = pc.createScript('startgame');

Startgame.prototype.initialize = function() {
    this.entity.script.sprite.on('click', this.onClick, this);
};

Startgame.prototype.onClick = function() {
    this.app.root.findByName('Level 1').enabled = true;
};

I am new to playcanvas. I tried this. and now both the scenes are merged together. do i have o disable something first? I want to launch game when play button is pressed in UI menu.

Yes you need disable the entity.

Yeah, you can right click on, say, the entity called ‘Level 1’ and select Disable. Or uncheck ‘Enabled’ for the entity in the Inspector panel. Then, you can enable it in script when you select the relevant button in your menu.

Yeah, i did it; Thanks for replying :slight_smile: