I am trying to run an animation from a nme variable?

I have not been able to find it in the documents.

I see something like this
new BABYLON.Animation("slide", 'position.x', 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);

and it would slide on the x position.
but something like this for the NME does not work

`new BABYLON.Animation("slide", 'material.getBlockByName("test_value").value', 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);`

but if i get the value and set it inside material like this
material.test_value = material.getBlockByName(“test_value”);
and run the animation like this, it works.
new BABYLON.Animation("slide", 'material.test_value.value', 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);

is there a way to get getBlockByName to work or is there a different way i should be doing this?

i am trying not to set a local value since these values could be anything.

Thank you.

Adding @Evgeni_Popov who played a lot with nme and might have way more insights than me :slight_smile:

Could you setup a repro PG, please, it will be easier to work with?

1 Like

here is the playground to explain what i am talking about.

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

Idealy a way for inside the animation configuration to target the NME value so i dont need to do the part that is wrapped in // ?

ok, i figured out a way, but its a lil bit fragile.

https://playground.babylonjs.com/#D89SW3#1

"property": "material.attachedBlocks.12.value",

since you cannot do material.attachedBlocks[12].value doing .12. worked. i assume getBlockByName() just goes through the attachedBlocks and looks for a name thats the same and returns that.

so i still have the question of: Is there a better way?

Only properties can be used in the property name, because the code is retrieving the value by doing property = property[index].

So, if propertyName is material.nodeScale.value it is doing:

  • property = sphere["material"]
  • then property = property["nodeScale"]
  • then property = property["value"]

You can see it won’t work if you have something like getBlockByName('NodeAlpha') as this is a function call, not a property. We would need to do something like eval which is not possible.

So I guess what you did is the best you can do, but as you said it’s really depending on the position of the block in the attachedBlocks array…