[SOLVED] Accessing Entity Assets with Code

Hello Team!

Thank you for creating this amazing Engine. I enjoy it very much. An amazing job!

A Question about Entity Assets:
I have a button which gets set a color depending on its status. I used following code:

 this.buttonMaterial = buttonMesh.material;
 this.buttonMaterial.diffuse.set(255, 0, 0); 

ButtonMesh is a Meshinstance of the Model. The problem being I have multiple instances of the model and all meshinstances are being updated. So I guess I am still only editing the model’s assets instead of its entity assets.

But I don’t really know how I can acces these entity materials. I tried accessing the model to get the materials but failed:

this.entity.model.materialAsset == null

asset

Thanks a lot for the help and the great product! :partying_face:

Hi @Sebastian and welcome,

This is a valid question, the way to do it is to update the shader/material values directly on the mesh instance.

That isn’t fully documented right now, but here is a forum post with instructions on how to do this:

Note the color values should be passed in the 0.0-1.0 range, not 0-255.

Let me know if this resolves your issue.

1 Like

Sir @Leonidas,

you are a hero.

Having provided the correct answer after a mere 19minutes is a job well done.
And thanks for pointing out the correct color values. This one might have caused me major headaches later on. :sweat:

Cheers to you! :beers:

1 Like