• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by gazialankus · Apr 22, 2012 at 03:47 PM · timeparticlesystemshurikenrewind

Rewind particle system (shuriken)

I would like to rewind a particle system. I believe I should be able to do it by setting the time property, as the scripting reference made me believe:

ParticleSystem.time
> Use this to read current playback time or to seek to a new playback time.

I see that we can rewind particle systems in the editor by scrubbing time. However I'm not having any luck with rewinding a particle system in code. Here's what I've been trying it with:

     public class RewindParticle : MonoBehaviour {
 
     public float AfterSeconds = 2.0f;
     public bool rewinded;
 
     private float rewindStartParticleTime;
     private float rewindStartTime;
 
     void Update () {
         if (rewinded) {
             float rewindToParticleTime = rewindStartParticleTime - (Time.time - rewindStartTime);
             if (rewindToParticleTime > 0.0f) {
                 Debug.Log("rewinding to time " + rewindToParticleTime);
                 particleSystem.time = rewindToParticleTime;
                 Debug.Log(particleSystem.time); //this corrently prints what rewindToParticleTime has
             }
         }
 
 
         if (particleSystem.time > AfterSeconds) {
             if (!rewinded) {
                 rewinded = true;
                 Debug.Log("rewinding");
                 rewindStartTime = Time.time;
                 rewindStartParticleTime = particleSystem.time;
                 //these didn't help either
                 //particleSystem.Stop(); //this stops it for good
                 //particleSystem.Pause(); //this just pauses it
             } 
         }
     }
 }

Here's what the output looks like. This starts after 2 seconds. I believe my code is correct:

rewinding
> rewinding to time 1.997295
> 1.997295
> rewinding to time 1.980445
> 1.980445

This goes on until it reaches close to zero. However, the particle system that I'm looking at doesn't care, it just plays as if I'm not setting the time property at all.

The conclusion that I reached so far is that this is a bug and Unity simply ignores setting the time property of ParticleSystem instances. Am I missing something or is this really a bug?

Thank you.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by ricardo_arango · Jan 24, 2013 at 07:18 PM

You need to set the random seed, to make sure you have a deterministic simulation and call ParticleSystem.Simulate (). For example:

 using UnityEngine;
 
 public class Rewind : MonoBehaviour {
     float time;
     public ParticleSystem particleSystem;
     void Start (){
         particleSystem.randomSeed = 1;
     }
     void OnGUI (){
         time = GUI.HorizontalSlider (new Rect(5,5, 200, 20), time, 0, 10);
         time = (int)time; // to animate the simulation in steps
         if (GUI.changed)
             particleSystem.Simulate (time, true, true)
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by gazialankus · Apr 24, 2012 at 12:38 AM

This is being answered in the forums: http://forum.unity3d.com/threads/133302-Can-t-rewind-a-ParticleSystem.-Bug

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dansav · Jan 22, 2013 at 10:15 AM 0
Share

Was this ever fixed. I can't find any info about anybody getting simulate to work for either rewinding or for going to time t for the particleSystem.

avatar image
0

Answer by Anxo · Sep 15, 2014 at 07:18 PM

Little Late but I needed the particle system to restart too, sadly this is how I had to go about it.

Summery:

 particleSystem.Clear();  // if you do not clear, it will keep old particles when you turn the object back on. 
 
 particleSystem.gameObject.SetActive(false);
 particleSystem.gameObject.SetActive(true);

This is how I use it.

 //Particle system is turn to play on awake. 
 
 private bool particlesShouldBeOn = false; // this is the bool that controls the particles
 void Start(){
      StartCoroutine(FlipParticlesOnAndOff());
 }
 
 IEnumerator FlipParticlesOnAndOff ()
         {
                 
                 while (true) {
                         myParticles.Stop (); //Stop the particle system 
                         while (particlesShouldBeOn == false)
                                 yield return null; //wait till bool flips
                         myParticles.Clear (); // clear any particles that remain.
                         myParticles.randomSeed = 0; // randomizing seed
                         halo.SetActive(false); // <--- work around as Stop() does 
                                                 //not rewind but Awake does....
                         halo.SetActive(true); // < -- start back up. 
                         while (isCharged)
                                 yield return null; // Wait till we flip the bool off
                 }
         }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Carwashh · Feb 25, 2016 at 05:52 PM 0
Share

Hey, I'm trying to implement this in my project, but not following everything.

Is this coroutine supposed to be running the entire time this game object is alive? and particlesShouldBeOn is used to start/stop the effect?

Line 11 - while what is true? Should that be a variable that is set elsewhere?

isCharged is changed where?

Thanks

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rewind particlesystem. Play it backward 1 Answer

Separate particle systems with duplicate behavior? 0 Answers

How to make particles react to movement of particle system 4 Answers

ParticleAnimator doesn't change color of particles in ParticleSystem(Shuriken) 0 Answers

IsFinite(outDistanceAlongView) Error 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges