Hello again
i have a request about updating a particle system during runtime. I would need to adjust the opacity during runtime to blend it in and out. I’ve attached the simple script below. The thing is: The particle system gets the value - if i console.log the adjustments, the key i change gets the right value, but the particle system dont change. Note: i’ve also included the particlesystem.rebuild() function, but that causes the particle system to stuck (it dont crash).
var ParticleOpacityController = pc.createScript('ParticleOpacityController');
// Opacity var for adjustments
ParticleOpacityController.attributes.add('opacity', {
type: 'number',
default: 1,
min: 0,
max: 1
});
// Initialize the script
ParticleOpacityController.prototype.initialize = function () {
// Get the entity by name
var snowEntity = this.app.root.findByName('Snow');
// Check if the entity exists
if (snowEntity) {
// Get the particle system component directly
this.particleSystem = snowEntity.particleSystem;
this.setOpacity(this.opacity);
} else {
console.error("Entity 'Snow' not found.");
}
};
// Function to set the opacity of the particle system
ParticleOpacityController.prototype.setOpacity = function (opacity) {
this.entity.particlesystem.alphaGraph.keys[1].value = opacity;
console.log(this.entity.particlesystem.alphaGraph.keys[1].value);
};
// Update the opacity during runtime
ParticleOpacityController.prototype.update = function () {
this.setOpacity(this.opacity);
};
Has somebody an idea if its general possible in PlayCanvas to adjust the opacity during runtime in PlayCanvas? After several tries i had to post it here. Not sure if PlayCanvas may doesnt support changing ParticleSystem values during runtime.
Thanks for your help / input!