Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Changing NumParticles at runtime?
#1
Hi there!

I'm trying to get a better control of the number of active particles from an ObiEmitter at any time, but it looks like changing the NumParticles in the ObiEmitter resets all the particle physic states (so I guess it's only meant to be initialized once and then left untouched...). Using the speed setting is not a safe enough option for me, as I need to generate an accurate number of particles, that increases over time.
Is there a way to work around this without needing to change how the ObiEmitter itself works? (I was thinking of pre-allocating a max number of particles using NumParticles, and then controlling the emission using a separate variable in ObiEmitter. But I don't like having to work around a lib, as it makes upgrades more complex to deal with Guiño )
Maybe that would be a nice feature?
Note: I'm currently on Obi Fluid 3.3 (or maybe 3.2), so maybe that has been fixed in the meantime in Obi Fluid 3.4?

Cheers!
Reply
#2
(28-04-2018, 02:05 AM)tooomg Wrote: Hi there!

I'm trying to get a better control of the number of active particles from an ObiEmitter at any time, but it looks like changing the NumParticles in the ObiEmitter resets all the particle physic states (so I guess it's only meant to be initialized once and then left untouched...). Using the speed setting is not a safe enough option for me, as I need to generate an accurate number of particles, that increases over time.
Is there a way to work around this without needing to change how the ObiEmitter itself works? (I was thinking of pre-allocating a max number of particles using NumParticles, and then controlling the emission using a separate variable in ObiEmitter. But I don't like having to work around a lib, as it makes upgrades more complex to deal with Guiño )
Maybe that would be a nice feature?
Note: I'm currently on Obi Fluid 3.3 (or maybe 3.2), so maybe that has been fixed in the meantime in Obi Fluid 3.4?

Cheers!

Hi,

ObiEmitter already works by preallocating a fixed amount of particles (NumParticles) and activating particles as they need to be emitted. This ensures zero garbage generation and no allocation overhead.

The ObiEmitter class has two methods: EmitParticle() and KillParticle() specifically designed to allow what you want to do. Note however that when emitting particles manually you need to be extra careful about their spacing, to avoid sudden pressure spikes. Each particle represents a small amount of mass, so if too many particles are spawned at once in the same place, the density (and the pressure) will skyrocket resulting in a sudden burst. That's why "speed" is used to control emission, as it controls both the emission speed and the amount of particles to ensure constant density.
Reply
#3
(30-04-2018, 08:44 AM)josemendez Wrote: Hi,

ObiEmitter already works by preallocating a fixed amount of particles (NumParticles) and activating particles as they need to be emitted. This ensures zero garbage generation and no allocation overhead.

The ObiEmitter class has two methods: EmitParticle() and KillParticle() specifically designed to allow what you want to do. Note however that when emitting particles manually you need to be extra careful about their spacing, to avoid sudden pressure spikes. Each particle represents a small amount of mass, so if too many particles are spawned at once in the same place, the density (and the pressure) will skyrocket resulting in a sudden burst. That's why "speed" is used to control emission, as it controls both the emission speed and the amount of particles to ensure constant density.

I also couldn't change the number of particles at runtime.

emitter.NumParticles = 40000;
StartCoroutine(emitter.Initialize);

"Initialize" didn't work bcs it's inaccessible due to its protection level. I have changed it from protected to "public" but it also didn't do the trick. Please, help me, thx.
Reply