Mouse Lock Activating For No Reason

I’ve been making a game a new mode for my game with its own custom controls and those controls work great except it keeps locking the cursor even when you leave the scene. it makes use of this line of code

this.app.mouse.on(“mousedown”, function () {
this.app.mouse.enablePointerLock();
}, this);

the thing is this code is only used in that one scene so I don’t get why it would keep working after the scene is unloaded is there a way to fix it?

Hi @WilliamBoersma31,

You need to detach any input handlers you manually attached when changing scenes. This won’t happen automatically.

For example:

// --- when entering the scene
this.app.mouse.on('mousedown', this.onMouseDown, this);

// --- when leaving the scene
this.app.mouse.off('mousedown', this.onMouseDown, this);

Ok Thanks