[SOLVED] How to change scenes using interface buttons

Can you double check the numbers?

https://playcanvas.com/editor/scene/916873
https://playcanvas.com/editor/scene/916876
https://playcanvas.com/editor/scene/916970
image

Hello! Is there also a console error?

Hello,

I don`t see console mistakes…=(

Do you already know what exactly is ‘not found’?

I think it cant find the scenes, because I see this report after clicking on buttons, but I`m not sure exactly…

Do you have a project link?

Great news, I will try to reboot my laptop…

Sorry it was the example project. Do you have a project link? Maybe I can see a mistake…

Yes, ofcourse:

https://playcanvas.com/editor/scene/916895

Pls let me know what do you think about it, I`m very new in it.

I also don’t have a lot of experience, but I can always help to find out where things go wrong.

Are you sure this code is oke:

    this.loadScene (this.sceneId, function () {
        // Once the new scene has been loaded, destroy the old one
        oldHierarchy.destroy ();
    });

I can’t find where you set this.sceneId.

Try to change this:

ChangingScenes.prototype.changeScenes = function() {
    // Get a reference to the current root object
    var oldHierarchy = this.app.root.findByName ('Root');
    
    // Load the new scene. The scene ID is found by loading the scene in the editor and 
    // taking the number from the URL
    // e.g. If the URL when Scene 1 is loaded is: https://playcanvas.com/editor/scene/475211
    // The ID is the number on the end (475211)
    this.loadScene (this.sceneId, function () {
        // Once the new scene has been loaded, destroy the old one
        oldHierarchy.destroy ();
    });
};

To this:

ChangingScenes.prototype.changeScenes = function(sceneId) {
    // Get a reference to the current root object
    var oldHierarchy = this.app.root.findByName ('Root');
    
    // Load the new scene. The scene ID is found by loading the scene in the editor and 
    // taking the number from the URL
    // e.g. If the URL when Scene 1 is loaded is: https://playcanvas.com/editor/scene/475211
    // The ID is the number on the end (475211)
    this.loadScene (sceneId, function () {
        // Once the new scene has been loaded, destroy the old one
        oldHierarchy.destroy ();
    });
};

If you add me to the project I can help better.

1 Like

Yes, you helped me, it works :ok_hand: :+1:

But now I figured out that I don`t have abilities to come back to my first page after chosing one scene among those three that I have… :crazy_face:

Great!

You need a button or something on every scene to go back to the ‘scene selection’ scene. I don’t know what kind of game you want to make, so I don’t know what is the best way in your case.

1 Like

Yes, because of your help I have base, I have some ideas of how to use that to finish my first step.

Thank you, now I have what to study!!!

1 Like

Sorry about the delay in my response @Ivan_Stratiichuk. My idea would be to have a selection scene in your game, that leads to every other scene. Then, in all the other scenes, you can have a back to selection button. That’s what I normally do in my games.

1 Like

Yep, I will add back button folowing the same logic of changing scene code, I will add this code to each scene but all this scenes will gave the same ID number of source scene, so it will back me to scene from which I started… :+1: :ok_hand: :sunglasses:

2 Likes

Hi @Leonidas I am trying to create a PlayCanvas scene that switches between two senes using a button and am trying to open the scene you posted as an example:

https://playcanvas.com/editor/scene/916857

However, it is not opening. Thanks ahead for any help.

Hi @Ian_Curtis,

The way I set this up is by having a scene manager that transports itself between scenes. To ensure that it only gets loaded once, I made an initialization scene that loads the first scene of my choosing and then uses app events fired by the buttons to change scenes from there.

Check out :

https://playcanvas.com/project/756176/overview/scene-manager

To see it at work.

2 Likes