Action manager is null

I am trying to trigger hover event over mesh. I saw that action manager would be solution but I get this error while trying to use it:
cannot set properties of null (setting ‘actionManager’)

here is what I wrote:

 const mesh = scene.getMeshById(mesh);

    mesh.actionManager = new BABYLON.ActionManager(scene);

    var hl = new BABYLON.HighlightLayer('hl1', scene, {
      isStroke: true,
    });

    //ON MOUSE ENTER
    mesh.actionManager.registerAction(
      new BABYLON.ExecuteCodeAction(
        BABYLON.ActionManager.OnPointerOverTrigger,
        function (ev) {
          scene.hoverCursor = 'pointer';
          hl.addMesh(mesh, BABYLON.Color3.Green());
        }
      )
    );

Basically I copied it from here https://www.babylonjs-playground.com/#21YCLG#61

It seems to me that there is something wrong with the parameter… It should not be the ID of the mesh you are looking for?

If you know mesh ID, it should be like (in TS):

scene.getMeshById(id:number);

Another option, if you don’t know mesh ID, to get it by its name (as in PG):

scene.getMeshByName(meshname:string)

The problem is that I already use it in my code and it works fine. But now my scene object is differente. On console log on line 162 scene object has meshes:Array(7)
On console log on line 253 scene object has meshes:Array(0)

So this would be the reason for getting null, but since I already have used it I am not sure why is my scene object differente.

Here is what I have.

Is there an event which I can use on pointer move over mesh?
Now I get results only when I enter the mesh.

The example you gave with OnPointerOverTrigger works fine. I am not sure what this._store[‘enabledMesh’] returns, never used it, but I suppose it is the mesh which was enabled if you clicked on it?

If I were you, I would try to debug the Javascript Code and find out the difference between the scenes. Return to the scene where everything is fine, then modify your code step by step until it is not working and look what is here unusual in the values or function call stack.

enabledMesh is id from a mesh, that’s why I use id.
Before I do it I have another question.
How can I get pickInfo on cursor moving over mesh?
Action manager has over and out. Which works fine when I enter, but doesnt do anything while moving.
I tried onPointerMove but it doesnt return the coordinates of the cursor nor anything about mesh. I am looking for an object like pointerInfo in scene.onPointerObservable.add((pointerInfo) => {} where I can get normal, face and position.
I want to hover and place decal there, just like click.

var pickinfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) { return mesh == ground; });
if (pickinfo.hit) {
 return pickinfo.pickedPoint;
}

To make code understandable for others, you should use names for variables and functions due to the Style Guide

e.g. if “mesh” is not a mesh object but a number (ID) then you shall use “meshID” … but even this is a bad style… because what sort of meshID is this for? Is it a targetMeshID or a sourceMeshID or a tempMeshID … If an other person reads your code he or she shouldn’t seek for the meaning of a variable or a function… it should be self explanativ.

Just a good advice of an old rabbit :wink:

1 Like

Thanks you rabbit, I havent been thinking about it.
Everythink is working.

2 Likes

I have a quick question.
Setting alpha property just adds background to it.
Am I able to set opacity to a decal?

You may try to use texture decals, also known as decal maps - Decals | Babylon.js Documentation

1 Like