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

Starting and Stopping Emitters in the new Shuriken Particle System?

Discussion in 'Scripting' started by gevarre, Jan 5, 2012.

Thread Status:
Not open for further replies.
  1. gevarre

    gevarre

    Joined:
    Jan 19, 2009
    Posts:
    132
    I've been playing with the new Shuriken particle system in 3.5, and they're great, but I can't seem to find a way to turn the emitter on and off through scripting. There doesn't appear to be an enable or emit property anymore, so I'm not sure what to do.

    I'm doing a networked game, so I have at least one example of a persistent system that needs to go on and off at various times. I don't want to respawn it every time because the network instantiation could cause hiccups for the players.

    I notice there is now a "Play On Awake" option, but it doesn't seem to do anything. I do like the new "Duration" setting, and that would be perfect if I could just figure out how to trigger it to start over. Any thoughts?
     
  2. kjetilh

    kjetilh

    Joined:
    Oct 1, 2010
    Posts:
    82
    There is a play method you can use to start a particlesystem.
     
  3. gevarre

    gevarre

    Joined:
    Jan 19, 2009
    Posts:
    132
    Cool. Care to explain how to use it or where to find more info on it? a search of the scripting reference only comes up with this:

    Code (csharp):
    1. ParticleSystem.Play
    2.  
    3. function Play () : void
    4.  
    5. Description
    6. Plays the particle system.
    7.  
    8. See Also: Stop, Pause functions.
    Nothing I've tried seems to work, though I've gotten lots of strange error messages I've never seen before.
     
  4. tyoc213

    tyoc213

    Joined:
    Nov 14, 2011
    Posts:
    168
    Paste the errors, always are useful for people that have reached the same problem. :).
     
  5. gevarre

    gevarre

    Joined:
    Jan 19, 2009
    Posts:
    132
    Sure. At this point I'm still guessing at how to set it up, but here's what I've tried:

    First, I tried just making a particle system and attaching this script directly to it:

    Code (csharp):
    1. function Update () {   
    2.     if (Input.GetButtonDown("Fire1")){
    3.     ParticleSystem.Play;       
    4.     }  
    5. }
    This results in the following error and doesn't compile:

    ...BCE0020: An instance of type 'UnityEngine.ParticleSystem' is required to access non static member 'Play'.

    Okay, so I think maybe I need to create a variable and assign the particle system to it and then play it, so I do this:

    Code (csharp):
    1. var myParticles : GameObject;
    2.  
    3. function Update () {   
    4.     if (Input.GetButtonDown("Fire1")){
    5.     myParticles.Play;      
    6.     }  
    7. }
    this time I get this, and still no compile:

    ...BCE0034: Expressions in statements must only be executed for their side-effects.

    I've also tried variations of "myParticles.particleSystem.Play;" and "myParticles.ParticleSystem.Play;" and get the same error, so I'm guessing it's just me not knowing the correct way to set it up, though I wouldn't be surprised if it doesn't work with the new system yet. It never even gets to the point where the script will compile for testing.

    Any ideas?
     
  6. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    I haven't read the 3.5 docs but if its a method it should be Play(); and not Play;
     
  7. gevarre

    gevarre

    Joined:
    Jan 19, 2009
    Posts:
    132
    Code (csharp):
    1.  
    Thanks. You don't give any kind of code example, so just guessing, I tried this (the script is still on the particle system):

    function Update () {
    if (Input.GetButtonDown("Fire1")){
    Play();
    }
    }

    But then I get this:

    ...BCE0005: Unknown identifier: 'Play'.
     
  8. profanicus

    profanicus

    Joined:
    Nov 23, 2009
    Posts:
    295
    Play is a function of the ParticleSystem component, so you need a reference to one to use it.
    Assuming the script is on your ParticleSystem as you mentioned:

    Code (csharp):
    1.  
    2. private var myParticles : ParticleSystem;
    3.  
    4. function Start()
    5. {
    6.     myParticles = GetComponent(ParticleSystem);
    7.  
    8.         // use Stop and Clear to stop and erase existing particles.
    9.         // You don't need this if you turn off PlayOnAwake manually. You should also turn off PreWarm if you want particles to start emitting "from scratch"
    10.     myParticles.Stop();
    11.     myParticles.Clear();
    12. }
    13.  
    14. function Update ()
    15. {  
    16.     if (Input.GetButtonDown("Fire1"))
    17.     {
    18.         myParticles.Play();
    19.     }
    20. }
    21.  
     
    alone1992 likes this.
  9. gevarre

    gevarre

    Joined:
    Jan 19, 2009
    Posts:
    132
    That worked perfectly. I knew I was missing a few steps.

    Thanks a lot :)
     
  10. Daniel G

    Daniel G

    Joined:
    Mar 5, 2013
    Posts:
    25
    I cant figure out how to play my particle effect for a duration of time only, I know about the inspector duration time and turning off the looping, however with i say backFireL.Play(); in a function Update, it plays it over and over as if its looping :p I understand why that happens, I just need to have a way around it? Is there any way to define that it only plays for the time duration specified in the inspector? or at least a way of defining how long it plays in the script.

    I am using java :D

    thanks
    Daniel
     
  11. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    Ur doin it rong.
     
    Zardify likes this.
  12. Fajlworks

    Fajlworks

    Joined:
    Sep 8, 2014
    Posts:
    344
    Dead threads should stay dead >_>
     
  13. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    Most forum engines have the ability to enforce that automatically. If that's what UT wanted, that's how it would work.
     
  14. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    They also want members to contribute worthwhile things when they reply to a thread. You should give it a shot.
     
    the_motionblur likes this.
  15. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    @KelsoMRK : My comment's intent is perfectly clear.

    You might want to consider spending less time attacking others for improper forum usage, and spend a bit more guiding others to find the faults in their own unanswered questions, you know, like me. What I see here is me trying to help the poor guy understand that what he wrote literally doesn't make any sense (though could be a typo that could mean a couple of different things), while you and @Fajlworks are contributing only Forum-Nazism.

    So yeah. Take your own advice.
     
  16. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    "Ur doin it rong" nearly 2 years after the post you're responding to and then this garbage another year later? Go bark up someone else's tree....
     
  17. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Dear mods. Please close thread before this gets crazy. Sincerely, probably everyone.
     
    Kiwasi and Fajlworks like this.
  18. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    @KelsoMRK: Still, you're coming back at me with ad hominem attacks on my style of answering (DH1 on Paul Graham's hierarchy of disagreement) without actually making a counterpoint. My arguments, however, are validated counterarguments (DH4).

    So I'm here on the Unity forums to discuss Unity. It sounds like you're here to attack others' writing as “garbage” and enforce your own rules upon the forum system. So you should probably go find the Attack Others' Writing And Impose Conversation-Hindering Standards forum. Slash tree.
     
  19. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    If you say so.

    BTW - what it actually looks like you're here to do is argue the validity of W3Schools and get 3 year old threads locked. I can already feel it coming on this one.
     
    Last edited: Mar 2, 2016
  20. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    So here - I'll let you off the hook if you can justify what the value add to the community was when you responded with
    641 days after the fact.
     
  21. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    MODS! HALP!!!
     
  22. Fajlworks

    Fajlworks

    Joined:
    Sep 8, 2014
    Posts:
    344
    I guess we will see a response in a year or two :D until then!
     
    KelsoMRK likes this.
  23. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    @KelsoMRK Okay, you're not understanding what you're doing wrong so I'm going to resort to being perfectly blunt with you:

    My reply was to @Daniel G, not you. You're not adding anything Unity-related to this discussion, only attacking me.

    So butt the frack out.
     
  24. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    @KelsoMRK

    And I already answered this above in comment #15.

    Sorry, you're just trolling me now. Reporting you for abuse.
     
  25. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    You're adorable, have fun with that :)

    If you need me I'll be over here responding to interesting conversations with worthwhile input in a timely manner.
     
  26. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    @KelsoMRK My mother taught me a very important peice of wisdom when I was young: “If you don't have anything nice to say, keep it to yourself.” I think this applies well to this situation.

    So can it, Garbage The Mouth.
     
    RavenOfCode likes this.
  27. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    How about you guys cool it before I ban you both until the end of time? Thanks. Annoys the hell out of me I have to put up with squabbling from the pair of you. It's me dealing with a ton of people reporting you both.
     
    jtsmith1287 and Kiwasi like this.
Thread Status:
Not open for further replies.