-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Scene update is called before create after being restarted when using multifile loader #4629
Description
Version
- Phaser Version: 3.18.1
- Operating system: MacOS
- Browser: Not Browser-Specific
Description
When using a multifile loader (in this case, phaser-tiled-json-external-loader), if a scene is restarted, the update method gets called before create runs the second time. If you check this.sys.isActive during these calls, it returns false, and yet the update is being run anyway.
Example Test Code
Demo: https://osmose-phaser-tiled-loader-update-issue.glitch.me/
Source code: https://glitch.com/edit/#!/osmose-phaser-tiled-loader-update-issue?path=public/client.js:6:0
Additional Information
The root of the issue seems to be that sys.sceneUpdate is initially a no-op, and is only set to the scene's actual update method once create is run for the first time. So on first load, update gets run by the SceneManager.step function a bunch of times before create runs, but it does nothing since sceneUpdate is unset.
When the scene is reset, however, sceneUpdate isn't cleared, so when this early-update-run behavior happens, it actually runs the update method for the scene, which may refer to values set in the create method.
I didn't make a PR because I'm unsure whether clearing sceneUpdate when a scene is restarted is good enough, or if the SceneManager shouldn't be running the step function until the scene is fully re-created, or something else.
This was originally reported on the loader repo: Osmose/phaser-tiled-json-external-loader#2