Change Value of posteffect at runtime

hi again :slight_smile:
added the sepia posteffect to my camera. The idea is to rise the amount while loading stuff and reduce when You can play again. Looks fine but seams not to be verry reliable :frowning: Sometime it’s work, sometime I’ve to switch the camera and the effect is there. change attribute value in the editor works 100%

Is there a way to force the camera to notice new value?

like refresh(), update()

Hi @Gurki,

You can definitely change posteffect shader uniforms on runtime. Can you post a sample Playcanvas project that reproduces your issue to take a look?

this is my project: Herbivore
But it’s a little bit confusing and chaotic :slight_smile:
When the hourglas is visible, the sepia effect should apear…

if (this.app.root.findByName(‘SkyCam’).findByName(‘Camera’).script.sepia.Amount != 1){
this.app.root.findByName(‘SkyCam’).findByName(‘Camera’).script.sepia.Amount = 1;
}

So, indeed it’s a big project, but I am fairly sure you just need to update the following in your code:

var cameraEntity = this.app.root.findByName('SkyCam').findByName('Camera');
if (cameraEntity.script.sepia.amount != 1){
   cameraEntity.script.sepia.amount = 1;
}

Notice how amount is fully lowercase, which is the case with this specific editor attribute. You use the initial property definition to target it, not its Title:

Sepia.attributes.add('amount', {
    type: 'number',
    default: 1,
    min: 0,
    max: 1,
    title: 'Amount'
});

Sorry about this :blush:
I’ve checked in the console, but also with a capital A…
So I’ve tracked something bad I’ve add to the cam somewhere
shame on me
Now it works like it should => solved

1 Like