Is there anyway to get the previous scene id/name after changing scene?

Hi,

Question: Was just wondering if there was any prebuilt solution to get the previous scene id or name after changing scene?

Example: You change scene from ‘Scene1’ to ‘Scene2’, is there something I can call now I am in ‘Scene2’ to know the previous scene was ‘Scene1’?

Many thanks,

James

No. There’s not a really a concept or knowledge of what scene is currently loaded or was previously loaded.

You could store the previous scene name/id in a global variable as a quick ‘fix’.

1 Like

Hi!

Here is my solution to this:

https://playcanvas.com/project/756176/

The demo project has an initial scene that additively loads the requested scenes by name and brings the scene manager with it. The console will throw an error if you immediately try to use the previous button on load, but you get the idea.

Definitely would love to hear from @yaustar or the rest of the community to see if this solution is frowned upon for some reason.

1 Like

I would probably do it more like this: https://playcanvas.com/editor/scene/1073332

Moving an entity around scenes is fine in your example @eproasim as Init scene never gets reloaded again. If it was, the app will throw an error as each Entity is given a unique id when it is created in the Editor and two Entities with the same ID cannot exist at the same time.

1 Like