Search Unity

Animation speed of a VFX Prefab

Discussion in 'Animation' started by Chromu, Sep 21, 2021.

  1. Chromu

    Chromu

    Joined:
    Mar 6, 2021
    Posts:
    2
    Hi guys,

    I've downloaded a VFX Prefab collection from the asset store.
    Got it to work and like it quite much, I'd just like to slow it down.

    Now there is a very handy "Play Controls" window that pops up whenever I select the prefab.
    It has a "Rate" slider, which lets me select the speed. Let's say for example I put mine to 20 and like the effect.

    However after selecting anything else in my Scene, it just resets to it's default speed again (100), how to I save my changes? There is no button on the Play Controls window that I can find that does that.

    Thanks in advance for your help! Play Controls.PNG
     
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    236
    Hey,

    Unfortunately, that window is just for previewing the particles. To my knowledge, to change the speed of a particle system without using code, you'll have to manually change the various velocity properties of each of the particle systems contained in your VFX prefab. This is a huge pain.

    Luckily, this isn't very difficult to do with code. I made a simple script to change a particle system's speed:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [ExecuteAlways]
    4. public class ParticleSystemSpeed : MonoBehaviour
    5. {
    6.     [SerializeField] float particleSpeed = 1f;
    7.  
    8.     ParticleSystem ps;
    9.  
    10.     void Start()
    11.     {
    12.         ps = GetComponent<ParticleSystem>();
    13.  
    14.         var main = ps.main;
    15.         main.simulationSpeed = particleSpeed;
    16.     }
    17. }
    Remove the [ExecuteAlways] line if you don't want this updating in the editor, and only at runtime.

    You need to attach this to every object in the VFX prefab with a ParticleSystem component, and then set the speed for each one in the inspector. There's definitely a more efficient way of doing this, but I don't know what your prefabs look like.

    To have the speed update in the editor, you'll need to reload the scene, or exit the prefab view, and re-enter it.

    If you have any questions, feel free to ask. Also, I've tested this briefly, but I've never needed to do anything like this before.
     
  3. Chromu

    Chromu

    Joined:
    Mar 6, 2021
    Posts:
    2
    Hi,

    Thank you very much for taking the time to write all that down!

    I'll be able to test it with the script soon, thank you!
     
    Unrighteouss likes this.
unityunity