Jump to content

No keyboard events on new scene


Recommended Posts


When loading a new level I dispose the old scene and create a new one. My input system observes a new scene was created, unsubscribes itself from the old one, and subscribes to the new scene.

The mouse events continue on as normal from the new scene but the keyboard events stop.
If I remove focus from the canvas, focus on another html element, and then return to the canvas, I begin to receive keyboard events again.

The 'keyboard info' console log stops when the new scene is attached to.

Am I missing something else that needs to be done to recapture the keyboard with a new scene?



attachScene(scene) {
    this.scene = scene
    this.onKeyboardObserver = scene.onKeyboardObservable.add((info) => {
      console.log('keyboard info', info);
    this.onMouseObserver = scene.onPointerObservable.add(this.handleBabylonOnPointer, BABYLON.PointerEventTypes.POINTERDOWN | BABYLON.PointerEventTypes.POINTERUP | BABYLON.PointerEventTypes.POINTERMOVE);
detachSecne(scene) {
    if (this.scene == undefined) { return }
    this.scene = undefined
    this.onKeyboardObserver = undefined
    this.onMouseObserver = undefined
createScene() {
    if (this.currentScene) {
    if (this._camera) {
      this._camera = undefined;
    // remove watched game objects
    Object.values(this.objects).forEach(object => this.removeObject(object)) 
    // reset material cache
    this.cachedMaterial = {}
    // create new scene
    let engine = this.engine
    this.currentScene = new BABYLON.Scene(engine)
    // create default min light level
    var light = new BABYLON.HemisphericLight("HemiLight", new BABYLON.Vector3(0, 1, 0), this.currentScene);
    light.color = new BABYLON.Color3(0,0,0)
    light.intensity = 2 * 0.1
    window.ambientLight = light


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...