phaserjs / phaserjs/phaser

Adding an exsting TimerEvent to scene.time.addEvent() doesn't work

Open
#7,314 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
40.3k
Forks
7.2k
PR merge metrics
No merged PRs in 30d

Description

Version

  • Phaser Version: 4.1.0

Description

In the scene.time.addEvent(instance) path. The intent looks like it would remove from wherever it currently is, reset it, re-add it. But the implementation sequences it incorrectly:

  1. removeEvent(event) → pushes to _pendingRemoval
  2. Resets elapsed, repeatCount, etc. (but not the callback)
  3. Pushes to _pendingInsertion

Then in preUpdate:

  1. Removals run first → event.destroy() → callback = undefined
  2. Insertions run second → event added to _active with no callback

This breaks for any existing instance, including timers already running in _active. The destroy wipes the callback before the re-insertion, so the timer advances normally but fires nothing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the scene.time.addEvent(instance) path and follow its interaction with removeEvent and preUpdate, including the _pendingRemoval, _pendingInsertion, and _active queues. Verify the existing TimerEvent can be re-added without losing its callback, and confirm that the timer advances and fires its callback after reinsertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.