godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Dynamically adjust the amount of particles emitted without clearing all the particles #5939

Open chrisb123 opened 1 year ago

chrisb123 commented 1 year ago

Describe the project you are working on

Change the amount of particles to visually indicate a change that does involve clearing existing particles

Describe the problem or limitation you are having in your project

Tho only way to change the amount of particles is to change the total amount which clears all particles

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Don't emit particles based on a user provided ratio. Particles live out their life as normal, when they are due for restart they are tested based the ratio they are not submitted

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

User enters a ratio number, eg. 0.01 means 1% of amount and 1.00 would be every particle. The default is 1 to avoid breaking existing projects

If this enhancement will not be used often, can it be worked around with a few lines of script?

It's particles best to fix this in engine. I have no idea of any other suitable solution

Is there a reason why this should be core and not an add-on in the asset library?

I have no idea how to efficiently solve this except for core. I have a working example in engine for cpu particles 2D & 3D that has this feature

https://discord.com/channels/212250894228652034/218361207990648832/1052569941888475136

image

clayjohn commented 1 year ago

It should be fairly straightforward to expose something like MultiMesh's visible_instance_count to quickly change the number of particles visible. I guess a downside is that the invisible particles would still get processed, but I guess that is desirable so that you can change the number without restarting

chrisb123 commented 1 year ago

If that is the case I am probably misunderstanding or missing something with how the process works, my solution required me to evenly distribute and disable particles in the array of all particles. For example to show 50% I had to disable every second particle not only show the first 50%. There may be a better solution or more that can be disabled in addition to what I have done but I found that CPU usage did drop a little when particle ratio was lowered

chrisb123 commented 1 year ago

CPU particles 3D ratio also completed GPU particles is different to the CPU, I have not looked into this