I’ve forked the Changing Scenes tutorial to test event-based scene switching and I’m running into the following issue where it only works when done within setTimeout(), despite testing with various event mechanisms. Could this be a bug or is it just a misunderstanding?
Oddly enough, the issue only occurs if there is an additional script attached to the entity which contains the changing-scene script, even if the additional script is disabled.
So I’ve updated the project with a new script attached to the camera.
It’s to do with the script order on the entity and the fact that destroy() is being called.
In this case, testScript.update() is being called after changingScenes.update(). However, if changingScenes.update() destroys the entity that it is attached to (which it does when it changes scenes), the engine still tries the call the testScript.update() even though the instance doesn’t exist and therefore throws an error.
Thank you for looking into this and providing such insight. I’ve forked your project and see that it works, however I’m unable to replicate the fix on my project. I’ve found that even removing the test script from the entity doesn’t even work. Only once the test script is deleted or not preloaded will it work correctly, unless changing scenes within setTimeout().
Forked the project
Added the script to both cameras in the scenes
Update the scene ids
Changed the order so it’s first in the order of execution
Works first time