Obi Official Forum
Bug / Crash Changing Num Particles in Runtime Stops Emission - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html)
+--- Thread: Bug / Crash Changing Num Particles in Runtime Stops Emission (/thread-1172.html)



Changing Num Particles in Runtime Stops Emission - Komsur - 10-05-2019

Hi,

I'm experimenting with changing the Num Particles field during run time, this causes the Active Particles to be set to 0, and all emission stops and the Editor needs a restart.

Any ideas?

Thanks.


RE: Changing Num Particles in Runtime Stops Emission - josemendez - 10-05-2019

(10-05-2019, 10:16 AM)Komsur Wrote: Hi,

I'm experimenting with changing the Num Particles field during run time, this causes the Active Particles to be set to 0, and all emission stops and the Editor needs a restart.

Any ideas?

Thanks.

You cannot change the size of the emitter's particle pool at runtime. This is because Obi is designed to preallocate memory when possible, to avoid CG spikes and memory allocation overhead.

Each actor (such as the ObiEmitter) allocates particles from the solver once, when it is initialized. Then it spawns particles from this pool by increasing the amount of ActiveParticles, when a particle dies it is returned to the pool by swapping it with the last active one and decreasing ActiveParticles.

So:
- NumParticles is the maximum amount of particles that can exist in the emitter, its pool size. This should not be changed at runtime, if you do then the emitter will be invalidated and all particles deactivated.

- ActiveParticles is the current amount of emitted particles, between 0 and NumParticles. This changes dynamically at runtime.


RE: Changing Num Particles in Runtime Stops Emission - Komsur - 13-05-2019

(10-05-2019, 11:05 AM)josemendez Wrote: You cannot change the size of the emitter's particle pool at runtime. This is because Obi is designed to preallocate memory when possible, to avoid CG spikes and memory allocation overhead.

Each actor (such as the ObiEmitter) allocates particles from the solver once, when it is initialized. Then it spawns particles from this pool by increasing the amount of ActiveParticles, when a particle dies it is returned to the pool by swapping it with the last active one and decreasing ActiveParticles.

So:
- NumParticles is the maximum amount of particles that can exist in the emitter, its pool size. This should not be changed at runtime, if you do then the emitter will be invalidated and all particles deactivated.

- ActiveParticles is the current amount of emitted particles, between 0 and NumParticles. This changes dynamically at runtime.
Okay, so, is there a way of forcing the amount of active particles? I see that it's a read-only field, so probably not.


RE: Changing Num Particles in Runtime Stops Emission - josemendez - 13-05-2019

(13-05-2019, 08:02 AM)Komsur Wrote: Okay, so, is there a way of forcing the amount of active particles? I see that it's a read-only field, so probably not.

Why'd you want to do that? this is entirely managed by the emitter, you should never need to modify the number of active particles directly. Moreover, the amount of particles used to represent a certain volume of fluid is automatically calculated from the resolution and emission speed. The pool size (num particles) is allowed to be set in order to cap the maximum amount of particles that can ever be active, but otherwise thinking in terms of particle count is discouraged. Unlike a regular particle system, the amount of fluid is expressed in volume units, not particle counts.

That being said, you can ensure a certain amount of particles is always active by setting the lifespan to inifinite, then using "Burst" emission mode so that all particles needed to cover the emission shape are emitted at once.


RE: Changing Num Particles in Runtime Stops Emission - Komsur - 13-05-2019

(13-05-2019, 08:29 AM)josemendez Wrote: Why'd you want to do that? this is entirely managed by the emitter, you should never need to modify the number of active particles directly. Moreover, the amount of particles used to represent a certain volume of fluid is automatically calculated from the resolution and emission speed. The pool size (num particles) is allowed to be set in order to cap the maximum amount of particles that can ever be active, but otherwise thinking in terms of particle count is discouraged. Unlike a regular particle system, the amount of fluid is expressed in volume units, not particle counts.

That being said, you can ensure a certain amount of particles is always active by setting the lifespan to inifinite, then using "Burst" emission mode so that all particles needed to cover the emission shape are emitted at once.


Ideally, I'd like to change the amount of fluid that is spawned based on a flow rate float value we're receiving from another program, as that float value would be dynamically changing and I'd like to avoid making two emitters for the low and high float values.


RE: Changing Num Particles in Runtime Stops Emission - josemendez - 13-05-2019

(13-05-2019, 02:02 PM)Komsur Wrote: Ideally, I'd like to change the amount of fluid that is spawned based on a flow rate float value we're receiving from another program, as that float value would be dynamically changing and I'd like to avoid making two emitters for the low and high float values.

The emitter's "speed" property controls both the amount of particles emitted per second and their speed, to maintain a constant (or as constant as possible, given the discrete nature of particle-based representations) flow. This is similar to how a real-life faucet works.

You might be able to directly set the emitter's speed to depend on your flow value, depending on what your value represents. I can give more details about how "speed" affects emission, if you need.


RE: Changing Num Particles in Runtime Stops Emission - vannorman - 25-07-2020

Hi, I have a vial of fluid that I'd like to dynamically fill up / empty using a single particle emitter. I cannot successfully control the total number of active particles from Obi Emitter. I tried setting the "max pool size" as suggested by @josemendez but this had no effect (sliding the slider all the way between 0 and 1). 

I just need to have a total particle count of 100 or so, then arbitrarily decide at runtime to only have 20 or 55 of those particles active. Using DeactivateParticle causes the particle system to fritz out. 

What is the recommended way to set the number of active particles?