Change scene give errors

Take a look here @steven https://playcanvas.com/editor/scene/468192 i hope to publish something more in november

1 Like

Hello again,just my thought, but if one use multiple scenes is better to not use the root element to put the scripts you can do that just if all the scripts in root are used in all scenes, since when u delete the entites u have to keep the root and that can cause some problem if one script is used just in 1 scene. Am i wrong?

I’m not 100% sure I understand your question.

From the sounds of it, it depends on the script. E.g If you create script which continuously rotates an object, that’s fine to be placed in a scene on the object that it is rotating as it doesn’t depend on anything else nor does anything else depend on it beyond the entity that it is attached to.

The problem comes when you have references to scripts/objects in scenes that get unloaded/deleted. You need to consider how your game deals with this scenario. Whether this will be changing the way the objects interact with each other or keeping track what is loaded and unloaded, it is a scenario you will have to deal with in open world style games.

Well i think i have dealed with the scripts that must or must not interact with different scenes, i have 1 more question, and i hope is the last i have a value depth in my script levels in root entity that must keep track of the player position in the dungeon, but if i change scene that value is kept or is resetted?

I don’t think it would change unless something in the project (another script, event, function call, etc) is causing it to

I have tried this a variable called base in Game.js placed in root, i change it from true to false when changing scene, in i print it with console.log when the new scene start it tell me true again…should i try a global variable?

Do you unload any scenes?

i just delete the entities in the scene i don’t need but i keep the root

Is there anywhere else in the code where that variable could be changed to true?

Hi @steven,

I seem to be facing a similar problem. However, I don’t exactly follow the callstack bit. Could you please explain that?