Controlling opacity on an entity

I have been combing the forum and found a few posts regarding setting opacity. I have been trying them but they are not working.

Here is my code.

on initialize:
this.mat = this.entity.model.meshInstances;

on a listener for the completion of a tween:

this.mat[0].setParameter("material_opacity", 0);
console.log(this.mat[0].material);
this.mat[0].material.update();

Here is the error code I am getting:

AnimatedNumber.js?id=13164727:32 Uncaught TypeError: this.mat[0].update is not a function
at script.AnimatedNumber.initialTweenComplete (AnimatedNumber.js?id=13164727:32)
at Tween.fire (playcanvas-stable.dbg.js:665)
at Tween.update (tween.js?id=13110028:398)
at TweenManager.update (tween.js?id=13110028:24)
at Application. (tween.js?id=13110028:665)
at Application.fire (playcanvas-stable.dbg.js:665)
at Application.update (playcanvas-stable.dbg.js:21929)
at playcanvas-stable.dbg.js:22282

Do you have a project that you can share that shows this issue?

Some things to note in the meantime:

  • If it’s a custom model, there may be more than one meshInstance
  • If it’s on a tween calback, is this is probably not pointing to the this you are thinking about

Thanks, unfortunately I can’t post because of the client. It’s from a .dae that I imported. I’ll step through that and see. I will also check on the this as well. I did onTweenComplete.bind(this) so it should be pointing to a correct place but it is good to know. I am also using webGL2.0. Would that make a difference?

Not that I know of.

Could you take part of the code and create a new public project with a cube to demo the issue?

Thanks for your help. Apparently it was confused because I was giving it a numeric value. If I converted it to a string it works fine.

Really? That’s odd. A numeric value should be fine :thinking:

Here’s the example I normally give for fading in and out. https://playcanvas.com/project/563874/overview/fading-objects-in-and-out-fix

I know. Completely baffled.