[SOLVED] Switching scenes via button

i tried it yesterday, its working now because i got rid of it

how do i do that?

In the example project are two scripts as far I have seen. A sceneManager script and a button script.

I think you need to add the sceneManager script to one of your entities of your menu scene and you need to enter the name of this scene in the attribute of the sceneManager script.

You need to add the button script to the start button of your menu scene. And add the name of the scene you want to load in the attribute of the button script.

Hi @Nicholas_Taylor,

If you look at the example project closely, you will need to create an empty scene with the name ‘Init’. In that scene, create an entity and attach the scene manager script to it. When the Scene Manager script is attached to that entity, you can choose the scene you with to load first by typing it’s name in the attribute box.

After that, you can add the button script to your button, or create you own. That script will fire an app level event that will then change the scene for you. When you have done these steps, you will want to launch your project from the Init scene.

I hope this is helpful

1 Like

Can this not be the scene you start with? Like a menu scene?

I’ve modified it to act that way before, but ultimately, I found it cleaner to have all of the items I needed to persist through scene changes be in a separate scene themselves.

As written, The Scene Manager assumes that it is in a Scene called Init and then automatically loads the first scene it is given. I would make the ‘First Scene’ the Main Menu and then use my events from there to change the scene. Using an Init scene is also to set the ‘Previous’ scene. If the previous scene was Init, it won’t try to load it

when I push the button it does nothing

Did you add the button script from the example project to your button? If you look at the script, it’s quite simple, and you can see the logic used to tell the scene manager to change the scene

don’t think so

ill go add it

Do I make the button a child entity of the 2d screen?

or component

it still does nothing:

The scene you linked to only has the button.js in the scene. The sceneManager script is not part of the scene so there isn’t anything listening for the event changeScene

so what do I do??(im a bit slow)

Add the sceneManager.js script in the scene somewhere

Im confused by ths

You may want to use the new scene loading helper code that I recently wrote from there: https://playcanvas.com/project/437633/overview/changing-scenes

It’s a bit simpler than the sceneManager.js script that is in your project

(See news feed for notes)

I’ll check it out, thanks

How do I make to where It only switches scenes on a press of a button

Here’s a really quick example of the method I mentioned before:


Ok, ill see what I can do with this, thank you!

It worked, thank you very much, youve been SUCH a big help, have a great day yaustar