Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to tween various settings on a Particle System efficiently?

Discussion in 'General Graphics' started by Jamez0r, Jan 21, 2020.

  1. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    205
    Hey guys, I'm creating a 2D rain particle effect. I need the rain to be able to get heavier (more particles, make raindrop sprites stretched a bit longer, change the angle of the raindrop and its velocity direction if it gets "windy") and lighter (less drops, etc).

    To do this, I want to tween each of those variables in the various modules. I've been reading up on how to change those module variables in a script, and I'm a bit worried about performance issues with how they are modified. According to my research you have to create a new MinMaxCurve every time you want to change any of those settings. Since I need to tween those settings (heavy rain -> light rain) its going to be creating those MinMaxCurves every frame during the tweening. In all of the examples I've seen, they are changing the MinMaxCurve once (like, on Start()), not every frame like I need to with tweening. I don't know if its intended or suggested to do this every frame while tweening.

    Here is the info I've been reading:
    How to change the variables in the Particle System modules: https://docs.unity3d.com/ScriptReference/ParticleSystem.MinMaxCurve.html
    Blog post about whats going on with the Particle System: https://blogs.unity3d.com/2016/04/20/particle-system-modules-faq/
    Forum post where a guy seems to be asking a similar question (with answer from Unity dev): https://forum.unity.com/threads/blog-post-particlesystem-modules-faq.398773/#post-3477197

    Could someone comment on how I can efficiently tween these module settings? Is it OK to be creating a "new MinMaxCurve()" every single frame for multiple modules when tweening?

    Would appreciate any help! Thanks !!!

    EDIT: Just to add a bit more info, I would be using "Constant Value", and "Value Between Two Constants" for everything. Don't need curves.
     
    Last edited: Jan 21, 2020
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    Hey,

    Indeed there are faster options than the full MinMaxCurve API. However, if you're only using the constant number modes, you should find it is reasonably quick. Here are the 3 options I think you have:

    1. Do what you're doing now - set the MinMaxCurve
    2. Use the "multiplier" variants of the particle properties, which just take a float, not a MinMaxCurve, eg: https://docs.unity3d.com/ScriptReference/ParticleSystem.MainModule-gravityModifierMultiplier.html This can be used to set the single constant, or the multiplier applied to a curve. It cannot be used to set the "Random between 2 constants"
    3. Bind an animation clip to the values you want to modify, and set the frame of the animation via script, to control the tweening. This may allow you to make the overall animation of the rain effect much more artist-driven, with only a single script value to set the rain strength. Then all other controls are authored via the animation. Not sure if this will prove to be faster or slower, but it is worth looking at.

    If you want the fastest solution, definitely profile all 3 (for option 2, you could mix it with 1, by only using the "multiplier" on properties that are using a single constant)

    Best of luck!
     
  3. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    205
    Thank you for the information!
     
    richardkettlewell likes this.