ExecuteCodeAction is not working on meshes when imported ES6 style

I am using babylonjs/core - 4.0.3 for my react project.

While importing the BabylonJs ES6 styles the action events are not firing for meshes

Code:

import { Scene } from '@babylonjs/core/scene';
import { Vector3 } from '@babylonjs/core/Maths/math';
import { FreeCamera } from '@babylonjs/core/Cameras/freeCamera';
import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
import { ActionManager } from '@babylonjs/core/Actions/actionManager';
import { ExecuteCodeAction } from '@babylonjs/core/Actions/directActions';
import { Mesh } from '@babylonjs/core/Meshes/mesh';
import '@babylonjs/core/Meshes/meshBuilder';

const createScene = function() {
  const scene = new Scene(engine);
  const camera = new FreeCamera('camera1', new Vector3(0, 5, -10), scene);

  camera.setTarget(Vector3.Zero());
  camera.attachControl(canvas, true);
  const light = new HemisphericLight('light1', new Vector3(0, 1, 0), scene);

  light.intensity = 0.7;
  const sphere = Mesh.CreateSphere('sphere1', 16, 2, scene);

  sphere.position.y = 1;

  scene.exclusiveDoubleMode = false;

  const meshes = [sphere];

  for (let i = 0; i < meshes.length; i++) {
    const mesh = meshes[i];

    mesh.actionManager = new ActionManager(scene);
    mesh.actionManager.registerAction(
      // the events wont fire for this code
      new ExecuteCodeAction(ActionManager.OnPickDownTrigger, (mesh) => {
        console.log(`mesh clicked`);
      })
    );
  }

  return scene;
};

But when the code is imported the legacy way the the events are fired.

Code:

import * as BABYLON from '@babylonjs/core/Legacy/legacy';
import { Scene } from '@babylonjs/core/scene';
import { Vector3 } from '@babylonjs/core/Maths/math';
import { FreeCamera } from '@babylonjs/core/Cameras/freeCamera';
import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
import { ActionManager } from '@babylonjs/core/Actions/actionManager';
import { Mesh } from '@babylonjs/core/Meshes/mesh';
import '@babylonjs/core/Meshes/meshBuilder';

const createScene = function() {
  const scene = new Scene(engine);
  const camera = new FreeCamera('camera1', new Vector3(0, 5, -10), scene);

  camera.setTarget(Vector3.Zero());
  camera.attachControl(canvas, true);
  const light = new HemisphericLight('light1', new Vector3(0, 1, 0), scene);

  light.intensity = 0.7;
  const sphere = Mesh.CreateSphere('sphere1', 16, 2, scene);

  sphere.position.y = 1;

  scene.exclusiveDoubleMode = false;

  const meshes = [sphere];

  for (let i = 0; i < meshes.length; i++) {
    const mesh = meshes[i];

    mesh.actionManager = new ActionManager(scene);
    mesh.actionManager.registerAction(
      // the code will execute in this case
      new BABYLON.ExecuteCodeAction(ActionManager.OnPickDownTrigger, (mesh) => {
        console.log(`mesh clicked`);
      })
    );
  }

  return scene;
};
1 Like

Hi @ganeshrnet . Welcome to the forum! No replies yet, huh? Is the issue still pending/active?

Bump. :slight_smile: In fact, rubber baby buggy bump. Calling all helpers. CQ-DX, CQ-DX.

Hey,
Hard to say. It looks good to me. Can you try to reproduce it here:https://codesandbox.io/
or in other editor using es6 modules?