Cannot read properties of undefined (reading 'copyTo') of particle system

I am getting this error. It appears when gun is shooting (_particleSystem.start() & _particleSystem.stop())

Now I was able to create reproducive playground:

steps to reproduce: open and close inspector several times (CTRL+I)

My workarround:
When I use my custom update function, and I want to use also the super usage, I need always call the super for all the particles:

    let superUpdate = this.particleSystem.updateFunction;
    this.particleSystem.updateFunction = (particles: any[]) => {
        //...
        superUpdate(particles); // superUpdate(partialPartices) -> partialPartices caused problems
        this.customUpdateParticles(customUpdateParticles);
    }

Stack:
Cannot read properties of undefined (reading ‘copyTo’)
TypeError: Cannot read properties of undefined (reading ‘copyTo’)
at ParticleSystem.recycleParticle (http://localhost:9000/main.0b191a83610c8be6362d.js:219719:30)
at ParticleSystem.updateFunction (http://localhost:9000/main.0b191a83610c8be6362d.js:219950:26)
at Water.particleSystem.updateFunction (http://localhost:9000/main.0b191a83610c8be6362d.js:17199:17)
at ParticleSystem._update (http://localhost:9000/main.0b191a83610c8be6362d.js:220683:14)
at ParticleSystem.animate (http://localhost:9000/main.0b191a83610c8be6362d.js:221048:14)
at ParticleSystem.start (http://localhost:9000/main.0b191a83610c8be6362d.js:220544:26)
at Water.splash (http://localhost:9000/main.0b191a83610c8be6362d.js:17237:33)
at ShootingGameMode.Shoot (http://localhost:9000/main.0b191a83610c8be6362d.js:15793:20)
at GameModeManager.Shoot (http://localhost:9000/main.0b191a83610c8be6362d.js:15601:31)
at HTMLCanvasElement. (http://localhost:9000/main.0b191a83610c8be6362d.js:15354:47)

cc @Evgeni_Popov

This PR will fix the problem:

2 Likes