# 'update' not working after restart a scene

**URL:** <https://phaser.discourse.group/t/update-not-working-after-restart-a-scene/14310>\
**Category:** Phaser 3\
**Created:** [May 11, 2024, 4:11am UTC](https://phaser.discourse.group/t/update-not-working-after-restart-a-scene/14310 "2024-05-11T04:11:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![VaJoy](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/vajoy/32/7841_2.png) [@VaJoy](https://phaser.discourse.group/u/VaJoy)\
**Post date:** [May 11, 2024, 4:11am UTC](https://phaser.discourse.group/t/update-not-working-after-restart-a-scene/14310/1 "2024-05-11T04:11:29Z")

</div>

Hi I’ve tried to reload a scene after remove/destroy it, but the `update` lifecycle method does NOT run again.

Here is my codes:

```javascript
/ **util.ts** /

export let pGame: Game | undefined
const initSceneName = 'init'
let curSceneName = initSceneName

class InitScene extends Scene {
}
pGame = new Game({
    ...phaserBaseConfig,
    scene: [],
})
pGame.scene.add(initSceneName, InitScene, true)

export const resetScene = (
  sceneName: string,
  scene: Phaser.Scene
) => {
  let newScene = pGame.scene.getScene(sceneName)?.scene

  if (!newScene) {
    pGame.scene.add(sceneName, scene)
  }

  pGame.scene.stop(curSceneName)
  pGame.scene.start(sceneName)

  curSceneName = sceneName
}

export const destroyScene = () => {
  resetScene(initSceneName, InitScene)
}

```

These methods be used like this:

```javascript
/ **test-scene.ts** /
  import { destroyScene, resetScene } from 'util.ts'

  class TestScene extends Scene {
    preload() {
      console.log('preload calls...')
      // preload some textures and sounds...
    }

    create() {
      console.log('create calls...')
      // some animations here...
    }

    update() {
      console.log('update calls...')
      // ...
    }
  }

  function initTestScene() {
    resetScene(
      'testScene',
      TestScene
    )
  }

  initTestScene() // runs well

  setTimeout(() => {
    destroyScene()
  }, 5000)

  setTimeout(() => {
    // 'preload' and 'create' will run (showing the logs by console.log, but no animation shows).
    // 'update' method of TestScene could not be triggered again.
    initTestScene()
  }, 8000)

```

IMO `update` should run again following `preload` and `create` methods after 8 secs, but this doesn’t happen (without error).

What’s more, none animation shows after 8 secs, althought the `preload` and `create` had been running.

This behavior confuses me so much, what can I do to fix it?

Thx!

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [May 11, 2024, 2:34pm UTC](https://phaser.discourse.group/t/update-not-working-after-restart-a-scene/14310/2 "2024-05-11T14:34:37Z")

</div>

Add logs for add, stop, start in resetScene.

---

<div class="post-metadata">

**Author:** ![VaJoy](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/vajoy/32/7841_2.png) [@VaJoy](https://phaser.discourse.group/u/VaJoy)\
**Post date:** [May 11, 2024, 4:36pm UTC](https://phaser.discourse.group/t/update-not-working-after-restart-a-scene/14310/3 "2024-05-11T16:36:14Z")

</div>

Sorry seems some methods of Phaser GameObject being rewrote inner `TestScene`, and I guess that the reason for this issue.

I will leave more details & solution here while I figure out this problem.

Plz just ignore this topic. ❤

---

<div class="post-metadata">

**Author:** ![VaJoy](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/vajoy/32/7841_2.png) [@VaJoy](https://phaser.discourse.group/u/VaJoy)\
**Post date:** [May 13, 2024, 3:05am UTC](https://phaser.discourse.group/t/update-not-working-after-restart-a-scene/14310/4 "2024-05-13T03:05:32Z")

</div>

I’ve got the final reason: `game.pause` called by `TestScene ` before swithing scenes.

The sollution is just resume the game while swithing scenes:

```javascript
export const resetScene = (
  sceneName: string,
  scene: Phaser.Scene
) => {
  if (pGame.isPaused) {
    pGame.resume() // resume game here!!!!!!!!!
  }

  // ...
}

```
