I am not sure what happened…I got it working now. It wasn’t working inside a settimeout…weird…anyways, thanks. How can I make a quick tween to fade in from 0 to 1 now?
A quick question regarding the opacity change via setMaterial:
I’m setting the opacity entity.render.meshInstances[0].material.setParameter('material_opacity', 0.5);
and it works well (ofc blendType is pc.BLEND_NORMAL).
But setting opacity on an entity does change the opacity on all other entites that use the same material.
Is it supposed behavior? As far as I remeber, setParameter would only affect that particular entity? Or am I wrong and I should use material.clone() on each entity?
In that case, as @Marks mentioned above, if I’d like to tween the opacity from 0 to 1, should I call material update in each frame? material.opacity = currentTweenValue; material.update();
Doesn’t it create additional overhead by reloading the shader every frame? I’ve been always thinking setParameter is much more fast way to do the same job
@Igor that’s a good point. No material.update() will not recompile the shader if it’s not required, but yes it has an overhead if you are calling it per frame.
I’d suggest you use setParameter for something like that, much like this example project does:
@Marks to tween a single value you need to use a different structure, check the example on the playcanvas-tween repo on how to do that:
// some object with a property called 'value'
var data = {
value: 0
};
// create a new tween using pc.Application#tween
// passing another object as the target. Any properties
// that are common between the target and the source object
// will be tweened
app.tween(data).to({value: 1}, 1.0, pc.BackOut);
Based on the issues you’ve described so far, it sounds like you’re running into a scope issue when attempting to tween the opacity. This also explains why it didn’t work for you inside of a timeout. Could you post the code you’re using to tween the opacity?