Getting error while assigning a material to a variable in an angular project

Hi,
I am getting below error. I am using same versions of babylon modules

Argument of type 'Material' is not assignable to parameter of type 'Node'.
  Type 'Material' is missing the following properties from type 'Node': _doNotSerialize, _isDisposed, _ranges, onReady, and 56 more

Thanks,
Jaya Kannan K R.

We will need to see the code, as the error message is saying you are trying to assign a Material to a property that is expecting a Node instead.

1 Like
let current_highlight_mesh = scene.getMeshByName(mesh.name);
                  let current_highlight_material =
                    current_highlight_mesh.material;
                  if (current_highlight_material) {
                      let highlightAnimation =
                        BABYLON.Animation.CreateAndStartAnimation(
                          'textureMove',
                          current_highlight_material,
                          'opacityTexture.vOffset',
                          -20,
                          60,
                          1,
                          0,
                          0
                        );
                      highlightAnimation.onAnimationEndObservable.add(() => {
                        current_highlight_mesh.material.dispose();
                        current_highlight_mesh.dispose();
                      });
                  }

FYI

Which line is generating the error?

let current_highlight_mesh = scene.getMeshByName(mesh.name);
let current_highlight_material =
current_highlight_mesh.material;
if (current_highlight_material) {
let highlightAnimation =
BABYLON.Animation.CreateAndStartAnimation(
‘textureMove’,
current_highlight_material,
‘opacityTexture.vOffset’,
-20,
60,
1,
0,
0
);
highlightAnimation.onAnimationEndObservable.add(() => {
current_highlight_mesh.material.dispose();
current_highlight_mesh.dispose();
});
}

The CreateAndStartAnimation only works with AbstractMesh.

See the doc: Advanced Animation Methods | Babylon.js Documentation

You could try:

BABYLON.Animation.CreateAndStartAnimation(
  'textureMove',
  current_highlight_mesh,
  'material.opacityTexture.vOffset',
  ...

but I’m not sure it is supported by the method.

1 Like

Still the error is there @Evgeni_Popov

It does work here:

https://playground.babylonjs.com/#RTWHNK

Note that you should not pass 0 as the “loopmode” parameter (8th parameter). Try BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE instead.

@Evgeni_Popov .After changing the 8th parameter also the error is there. If I assign that material to a global variable, there error will not there. But If I assign it to a local variable, it shows this error

Well, as shown above, it does work in my Playground.

So I think you will need to provide a repro if you want us to be able to help more.

@jayakannan , please provide repros in the playground for your issues as it is almost impossible to troubleshoot without them :wink: