WARNING : This site is outdated and the PopcornFX team will no longer answer your questions here.
For all support questions please go to our Discord server
0 like 0 dislike
1.8k views
As i am totally new to the Popcorn FX asset for unity i have trouble finding a function that plays and one that pauses the emission of an effect via script on runtime. I have already tried to use the particleSystem.Pause() and the particleSystem.Play() functions but these wont seem to work on the Popcorn Fx effects.
 

 

regards Julian Kaulitzki
by

1 Answer

0 like 0 dislike
 
Best answer

Hi Julian,

The "particleSystem.Pause()" and "particleSystem.Play()" methods are only for the Shuriken particle effects, which is the default Unity particle system, so it's normal that this doesn't work with your PopcornFx effects.

You can access the PkFxFX component via your script and then call the methods "StartEffect" and "StopEffect":

http://wiki.popcornfx.com/index.php/PKFxFX_component

Here is an example of a script starting the effect after 3 seconds and stopping it after 5 seconds:

public class testScript : MonoBehaviour
{
    public PKFxFX effectToPlay;

    private float stopEffectTime = 0.0f;
    private bool effectStarted = false;

    // Update is called once per frame
    void Update ()
    {
        stopEffectTime += Time.deltaTime;
        if (stopEffectTime > 3.0f && effectStarted == false)
        {
            effectToPlay.StartEffect();
            effectStarted = true;
        }
        if (stopEffectTime > 5.0f && effectStarted == true)
            effectToPlay.StopEffect();
    }
}

If you want to freeze all the particle effects, then you can set the "m_TimeMultiplier" attribute of the "PkFxRenderingPlugin" component, which is attached to your camera, to 0. This will pause all the particle effects in your scene.

If you want to freeze only one effect, you will have to create a special attribute for this effect and use it to change the behavior of the particles in your PopcornFx scripts.

Hope this helps you understand how our tool is working!

by Paul (8k points)
Hey there,
thank you for answering that quickly but i already tried your solution and i just could not get my head around this. So I if I understand that the right way I have to add the PkFxFX component to the GameObject with the particle effect on it and then I have to save a reference of this effect to my streaming assets folder so i can add it to the object field of the PkFxFX component in order to access it?

regards Julian Kaulitzki
Everything should be explained here:

http://wiki.popcornfx.com/index.php/Category:Unity

Once your effect is baked in the Assets/StreamingAssets/PackFX folder, you just create a GameObject with the PkFxFX component attached to it (or right click on the Hierarchy -> Create PopcornFX -> Empty Effect) and drag and drop (or select) the .pkfx you want in the FX field.
Once this is done, you can control your effect by accessing the PkFxFX component on this GameObject as I have explained in my previous message.
ahhh of course that makes sense! Thank you for your patience, i was totally heading the wrong direction.

regards Julian Kaulitzki
No problem, glad I could help you!
...