Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Moving a ParticleSystem - why does Unity interpolate its position?

Discussion in 'Editor & General Support' started by Banderous, Apr 30, 2012.

  1. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    I have a particle system that emits all of its particles in an immediate burst, since it represents a bullet impact. The particle system is moved to the point of impact (by modifying its gameobject.transform.position), before 'Emit()' is called. The particles must not follow the emitter once they have been emitted, so the particle system is set to simulate in 'world space'.

    The problem is that particles appear in incorrect positions, particularly when the frame rate is low - it seems that the particle system interpolates the location of the emitter between its old and new positions over a number of frames, which I confirmed by adding a delay between updating the location of the particle system and the call to Emit().

    Has anyone else encountered this behaviour? It seems elementary - how are we supposed to create effects like this (created with the legacy system) if this is the case?
     
  2. lance2185

    lance2185

    Joined:
    Jun 22, 2010
    Posts:
    40
    Banderous,
    I would need to see the code in order to figure out what's happening with this. I do have a suggestion regarding another way to achieve the effect you are looking for, though: One of the ways that I create my OnHit weapon effects is to simply instantiate a prefab of that effect. Then it already has its position when it is created.

    If you want to continue with the code you've written, however, I think people will need to see that code in order to determine what is going on.

    Regards,
    -Lance
     
  3. _Petroz

    _Petroz

    Joined:
    May 13, 2010
    Posts:
    730
    Make sure emitter.emit is set to false. The emit property will make it emit each frame in addition the burst from Emit()
     
    Last edited: Apr 30, 2012
  4. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Petroz - this is in reference to the new 3.5 particle system. ParticleEmitter appears to be a component of the legacy system.

    Lance2185 - Thanks for the suggestion, but instantiating a particle system for each bullet impact entails significant overhead, and each particle system uses its own draw call.

    Note - and this is crucial - the problem only reproduces in low framerate situations. To reliably reproduce this on my desktop I change my 'fixedTimestep' in project time settings to the minimum value (0.0001).

    Here's an excerpt from the class I'm using to manager the single particle system:

    public ParticleSystem explodingSystem;

    public void spawnExplosion(Vector3 location, float maxRange, float damage) {
    explodingSystem.transform.position = location;
    explodingSystem.Emit(20);
    ...
    }


    Pretty simple. I will try and put together a unity package that reproduces the problem.
     
  5. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
  6. d.eisenga

    d.eisenga

    Joined:
    Sep 14, 2011
    Posts:
    43
    I've also run into issues with particle bursts when using Time.captureFramerate - particles firing in the wrong position and direction - which didn't happen without it. Possibly related?
     
  7. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    d.eisenga - yes, most certainly. I wasn't aware of Time.captureFramerate as a way to lock framerate, otherwise I'd have used it in my repro.

    FYI Unity have accepted this as a bug - 461698.
     
  8. jonboris

    jonboris

    Joined:
    Jan 8, 2009
    Posts:
    78
    I'm having exactly the same problem, have been googling all day for solutions!

    Can't believe more people aren't complaining about this?
     
  9. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    That was my reaction, and it's why I was hesitant to raise it as a bug straight away. Moving a single particle system is key to getting a lot of particles on screen at a decent frame rate, I don't know how else one would do bullet impact effects. I guess people haven't migrated from the old particle system, but still.
     
  10. RElam

    RElam

    Joined:
    Nov 16, 2009
    Posts:
    375
    I'm finding that virtually any effect using world space is screwy. Even instantiating an effect and immediately moving it (so in effect this happens in zero time) and playing it manually will still cause this odd interpolation.
     
  11. Patapouffe

    Patapouffe

    Joined:
    Apr 3, 2010
    Posts:
    88
    Having the same problem here with the interpolated particle system ! Lower frame rate makes this even worse. Its makes creating this effect impossible on iOS while keeping good performance. Unity please fix this interpolation issue!
     
  12. Papatsu

    Papatsu

    Joined:
    Apr 8, 2010
    Posts:
    32
    We just came up with a workaround for this problem on one of our upcoming iOS-titles.

    Code (csharp):
    1.  
    2. ps.transform.position = new Vector3(0, 100, 0);
    3. ps.Simulate(0.005f, true);
    4. ps.Play(true);
    5.  
    We haven't really experimented with how short you can simulate, but so far it works great for us!
     
    kreso and samana1407 like this.
  13. StubbornMinion

    StubbornMinion

    Joined:
    Apr 13, 2012
    Posts:
    4
    Papatsu, thanks for your workaround, it's helped me with my problem.

    For reference here's the issue in detail:
    I have a grid of GameObjects - basically, think the invaders of space invaders. They are moved left to right in discrete timed chunks, rather than smoothly animated. The Invader prefab has a ParticleSystem on it, which is set to go off when the invader dies.

    What happens however is that in local space it's fine, but in world space it seems not to work at all, although on closer inspection you can sometimes - sometimes - see a few errant particles. The lack of the whole system in all its glory is very confusing; I can't tell if the system is out of position, hugley scaled up, or misfiring in some other way.

    If I click the invader in the scene view and press the 'Simulate' button in the Particle Effect dialogue box, the same thing happens (usually nothing, occasionally something very wrong). On the second press however, it works. Perfectly. Again, in local space all of this behaves as expected, first time.

    Using Papatsu's trick of simulating it slightly first has fixed the problem for me.
     
  14. db82

    db82

    Joined:
    Mar 14, 2012
    Posts:
    24
    As an alternative to using Simulate(0.005f), this works for me if you need to move the system multiple times in one function call

    Note: set the particle system to use WORLD space.

    Code (csharp):
    1.  
    2. ParticleSystem system;
    3. Vector3  position = Vector3.zero;
    4.  
    5. while(true)
    6. {
    7.    position.x += 10;
    8.    system.transform.localPosition = position;
    9.    system.gameObject.SetActiveRecursively(false);
    10.    system.gameObject.SetActiveRecursively(true);
    11.    system.Play(true);
    12.  
    13.    yield return new WaitForEndOfFrame();
    14. }
    15.  
    16.  
    You still get a slight delay between bursts while unity WaitForEndOfFrame executes.
     
  15. DDowell

    DDowell

    Joined:
    Feb 8, 2012
    Posts:
    52
    This bug is still present in 4.0.0.f5. And in Flash, the workaround doesn't work around. Any news on this getting fixed?
     
  16. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    This was clearly never fixed, yet the bug I raised was closed as fixed with the comment:

    "The issue has been fixed and therefore the case has been closed"

    In fact I have already tried to reopen it once having found that it isn't fixed, I'll try to reopen it again.
     
    Last edited: Nov 8, 2012
  17. tayl0r

    tayl0r

    Joined:
    Jan 6, 2012
    Posts:
    85
    Still happening to me on 3.5.6f4

    Code (csharp):
    1.         if (m_particlePool.Count == 0) {
    2.             particle = Instantiate(m_coinSplashParticle, new Vector3(pos.x, m_particleYPos.position.y, pos.z), Quaternion.Euler(270f, 0f, 0f)) as CoinSplashParticle;
    3.         } else {
    4.             particle = m_particlePool.Dequeue();
    5.             particle._t.position = new Vector3(pos.x, m_particleYPos.position.y, pos.z);
    6.         }
    7.         yield return new WaitForEndOfFrame();
    8.         particle._particle.Play();
    9.  
    If the particle comes from the pool it will play halfway between the old and new position =\
    The interpolation bug seems to be the culprit if I had to guess.

    I thought maybe yielding until the end of frame would fix it but it doesn't. I also tried yielding for a whole second and it still doesn't play in the right position. The simulate() workaround did the trick though.
     
    Last edited: Nov 13, 2012
  18. akutruff

    akutruff

    Joined:
    Jul 24, 2009
    Posts:
    44
    I am trying to recycle my particles. I have one sub emitter set to world space. I SetActive(false) on the entire hierarchy. When I want to reuse the particle system, I move the particle system to it's new starting position, and then call SetActive(true). I then see a streak across my screen because it is interpolating between the sub emitters old position and new position.

    Why is the bug closed?
     
  19. tommy_smashworx

    tommy_smashworx

    Joined:
    Mar 5, 2013
    Posts:
    1
    I had this problem if I used Play(); and Stop(); but using enableEmission = true/false rectified it.
     
  20. nocanwin

    nocanwin

    Joined:
    May 7, 2009
    Posts:
    176
    Still broken on 4.2. I'm sure they'll get to it in 5. They need to give us a reason to upgrade right? It's the Adobe model of software updates. ;)

    Simulate(0.0001f) hack works for me.
     
  21. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    Just to let you guys know, this need to be done yet in 4.3 =/

    Code (csharp):
    1. foreach (ParticleSystem tParticleSystem in cachedEmitters)
    2.         {
    3.             tParticleSystem.Simulate(0.00001f, true);
    4.             tParticleSystem.Play(true);
    5.         }
     
  22. topherr

    topherr

    Joined:
    Jun 1, 2013
    Posts:
    25

    Same issue in 4.2.2f1

    It's frankly insulting that this bug is here for so long. Come on get it together.
     
  23. DavidC02

    DavidC02

    Joined:
    Jul 19, 2011
    Posts:
    152
    Hey guys,

    The Simulate hack works for me, but only the first time I run Play on the ParticleEmitter, if I want to run it again (without having to Instantiate the Particle System again), it doesn't show anything. Is there a work around for this?

    Thanks.
     
  24. DavidC02

    DavidC02

    Joined:
    Jul 19, 2011
    Posts:
    152
    I was trying this out, but it didn't work, the first time it works fine, but the second, it doesn't seem to play anything.

    Code (csharp):
    1.  
    2. hurtParticleSystem.particleSystem.Clear();
    3. hurtParticleSystem.particleSystem.Simulate(0.0001f, false, false);
    4. hurtParticleSystem.particleSystem.Play(false);
    5.  
     
  25. DavidC02

    DavidC02

    Joined:
    Jul 19, 2011
    Posts:
    152
  26. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    actually that will work now as a work around

    unity 4 Shuriken will batch all emitters that use the same material {however Render mode = Mesh IIRC might break that}
    of course creating a giant atlas of particles takes some work
     
  27. Cameron-Petty

    Cameron-Petty

    Joined:
    Jan 10, 2012
    Posts:
    11
    Unity 4.3.3f1 - using the simulate hack here, as well.

    Filed another bug report.

    Many thanks, Papatsu, for sharing that work around!
     
  28. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    781
    Cameron, have you got a link to the new bug, particularly in the new Issue Tracker?

    Disappointing that the original bug for this was closed, but thanks Papatsu for the excellent workaround.
     
  29. BigGreenPillow

    BigGreenPillow

    Joined:
    Dec 2, 2013
    Posts:
    26
    Having the same issue, does the simulate work around always reset the particlesystem?

    I'm trying to use it with a blood particlesystem and every time I need to play it in a different location it resets the state of the old particles.
     
  30. ChrisYummi

    ChrisYummi

    Joined:
    Jul 5, 2012
    Posts:
    8
    Oh my god, this is still not fixed! Just hit it today and I look at how long this thread has been going. Shame on you Unity - shame on you.

    Unity is about making your workflow easier, but this has probably wasted months of peoples time in total.
     
  31. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    781
    Last edited: Apr 24, 2014
  32. josessito

    josessito

    Joined:
    Feb 14, 2014
    Posts:
    57
    HI, I was having the same problem. I had a particle attached to a child of an object I wanted to move around, and after a trigger, the particle system would start emitting (it was not a burst emission.) After I change the simulation space from "world" to "local" the issue was fixed. If else someone has this issue you should try that.
     
  33. akuczera

    akuczera

    Joined:
    Feb 13, 2014
    Posts:
    15
    This bug..... so annoying.
    I found a solution by myself.

    Disable the gameobject then just clone, move to the position and enable it. After you are done destroy it.
     
  34. ForrestX

    ForrestX

    Joined:
    Apr 17, 2010
    Posts:
    94
    Bug still there in 4.5 ...
     
  35. ForrestX

    ForrestX

    Joined:
    Apr 17, 2010
    Posts:
    94
    Cmon we can't instantiate a new particlesystem every time...
    this bug is 2 years old..it's time to fix it.
     
  36. ForrestX

    ForrestX

    Joined:
    Apr 17, 2010
    Posts:
    94
    The last update didn't fix the issue...?!
     
  37. ForrestX

    ForrestX

    Joined:
    Apr 17, 2010
    Posts:
    94
    No it didn't fix it... (4.5.4f1)

    EDIT: if you change the project time to 2 (instead of 1), the issue is continous..

    The problem is activating the gameobject and the particle system togheter.
    Logging the position at first frame it results zero, therefore I suppose unity needs an update cycle to update the position...
    is there a workaround?how can I update the position manually without waiting one frame??
    Is Unity support aware of this issue??
     
    Last edited: Sep 26, 2014
  38. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    781
    Did you try Papatsu's workaround?

     
  39. ForrestX

    ForrestX

    Joined:
    Apr 17, 2010
    Posts:
    94
    Yes I tried it, but it doesn't work for me. I have particles on burst time 0 and they don't start anymore.
    It would have been resolved in 4.5.3 as stated here ?
    • Shuriken: Fix for re-enabled particle system which was disabled before it has finished
    Very disappointed...
     
  40. Aedous

    Aedous

    Joined:
    Jun 20, 2009
    Posts:
    244
    I'm not sure if this will help anyone, but I had a similar issue when trying to figure out why my particles where emitting in the wrong position at a low frame rate.

    I've only checked it out using the Shuriken System, and using Unity 4.6. I have a script attached to my particles and I'm calling ParticleSystem.Clear() on Start() on every particle system in the gameobject.
    Code (CSharp):
    1.  
    2.  
    3.     ParticleSystem[] ps;
    4.  
    5.     // Use this for initialization
    6.     void Start()
    7.     {
    8.         ps = GetComponentsInChildren<ParticleSystem>();
    9.         foreach (ParticleSystem p in ps)
    10.         {
    11.             p.Clear(true);
    12.         }
    13.      }
    14.  
    My particles are all using worldspace and constantly emitting, not using bursts. That seemed to stop the particles emitting at the wrong spots, but will have to play around to see if it happens again :(.

    After some tests : After a few tries, I ended up also using Papatsu's method as well for particles that use burst emission.

    Code (CSharp):
    1. ps.Clear();
    2. ps.Simulate(0.0001f, false, true);
    3. ps.Play();
    It seemed to have completely fixed the problem, hoping that would help point some people in the right direction.

    Hope it helps!
     
    Last edited: Oct 26, 2014
  41. Andy-Lee

    Andy-Lee

    Joined:
    Aug 16, 2014
    Posts:
    26
    But what if I want to keep the previous particles? The approaches above will clear them. :(

    Edit: Just after posting, I could think of a solution to solve this problem and have successfully get it to work -
    1. Use particleSystem.GetParticles to store the particles. You may also need to store particles for the child particle systems.
    2. Call particleSystem.Simulate or gameObject.SetActive(false); gameObject.SetActive(true); and move the particle system to the desired position.
    3. Use particleSystem.SetParticles to assign back the particles in step 1 to their particle systems.

    Also, I found that Simulate(0f) and do the job. No need to use some weird numbers like 0.0001f. :D

    Our particle systems work happily now even the frame rate is low. But we are still looking forward to the official fix on this problem.
     
    Last edited: Nov 19, 2014
    RonTang likes this.
  42. spotlightor

    spotlightor

    Joined:
    Jun 25, 2010
    Posts:
    15
    I found this problem using WorldSpace ParticleSystem with particles burst at time 0.
    I solved this problem by delaying the burst time a little bit (e.g. 0.05 second).
     
    yashpal likes this.
  43. bug5532

    bug5532

    Joined:
    Aug 16, 2011
    Posts:
    307
    Bug still there in Unity 5.0 RC2
    Workaround is working for position, but not 100% for rotation :(
     
  44. ronjart

    ronjart

    Joined:
    May 16, 2013
    Posts:
    100
    Im using RC4 and have the same problem. The hack is not working for me... The system wont start playing again.
     
  45. Skyboard_Studios

    Skyboard_Studios

    Joined:
    Jul 20, 2013
    Posts:
    51
    Bump!
    Unity3D 5.0.0f4
    I have just ran into this issue when pooling particle systems (water splash). Seems everytime I restart the particle system it moves slightly....

    I made a little video showing the bug. If you look in the Scene window you will see the particlesystem reference icon moving down after each instantiation.



    I will try the workarounds and see what happens.

    update: workarounds did not help. I thought I would try to avoid using the particle system with my pooling system and here are the results...



    Still not working.. you can easily see the particle system continually spawning lower and lower....

    Update:

    I managed to get it working! After lots of testing and configuring I determined that i was trying to position the particles in a position that was not accurate based on the JellySprite plugin that I was using.

    Code (CSharp):
    1.     public void OnJellyTriggerExit2D(JellySprite.JellyCollider2D col)
    2.     {
    3.        
    4.         Debug.Log("OnJellyTriggerEnter2D Trigger Exit " + col.Collider2D.name);
    5.         if (col.Collider2D.name == "Water") {
    6.            
    7.             lastsplash = CFX_SpawnSystem.GetNextObject(watersplash);
    8.             lastsplash.transform.position = col.ReferencePoint.transform.position;
    9.            
    10.         }
    11.     }
    using pooling system from Cartoon FX and JellySprite.



    Whoo hoo!
     
    Last edited: Mar 16, 2015
  46. goatytimes

    goatytimes

    Joined:
    Sep 23, 2013
    Posts:
    9
    Wow. I can't believe something as commonplace as this is actually a bug, I figured it was something I did wrong.

    Using Emit(particle#) instead of Play() seems to solve this issue for me. Though if I ever require something more advanced than one particle burst I may need to try the other workarounds here.
     
  47. ufoRomantics

    ufoRomantics

    Joined:
    Aug 1, 2013
    Posts:
    4
    Oh crap:/ I just wasted 3 hours trying to fix the very same issue on my own.I gonna try these workarounds right now...

    edit: spotlightor's workaround worked for me (delaying the burst time)
     
    Last edited: Jul 13, 2015
  48. geroppo

    geroppo

    Joined:
    Dec 24, 2012
    Posts:
    140
    Unity 5.1 bug still here :/

    Papatsu's solution worked for me, I was using distance emission
     
    Rodolfo-Rubens likes this.
  49. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,197
    I'm having the same issue! 5.1.2p1
    Did someone reported this bug so I can vote?
     
  50. tedd-hansen

    tedd-hansen

    Joined:
    Oct 26, 2014
    Posts:
    3
    Did a small test here in reusing particlesystem. Found a problem with some particles being emitted between locations.
    Using Unity 5.1.2f1.

    I have highlighted some of them (there should be only 3 streams).

    UnityParticleTest.png
    Steps to reproduce:
    1. Add "Afterburner" prefab from ParticleSystems asset.
    2. Change "Start lifetime" to 10 seconds and "Start speed" to 8.
    3. Attach script from bellow to a gameobject in your scene.
    4. Link "Particle System" property on script with "Afterburner" instance in scene. (aka, drag it over to the script)
    5. Play around with "WaitForSeconds(0.5f)" value to see how particlesystem reacts.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class ParticleTest : MonoBehaviour
    6. {
    7.     public ParticleSystem ParticleSystem1;
    8.     public List<Vector3> Locations = new List<Vector3>();
    9.     public int Current = -1;
    10.  
    11.     // Use this for initialization
    12.     private void Start()
    13.     {
    14.         Locations.Add(Vector3.zero);
    15.         Locations.Add(Vector3.up * 5);
    16.         Locations.Add(Vector3.down * 5);
    17.         StartCoroutine(MoveAround());
    18.         ParticleSystem1.Stop();
    19.     }
    20.  
    21.     public IEnumerator MoveAround()
    22.     {
    23.         ParticleSystem1.simulationSpace = ParticleSystemSimulationSpace.World;
    24.         while (true)
    25.         {
    26.             yield return new WaitForSeconds(0.05f);
    27.  
    28.             Current++;
    29.             if (Current >= Locations.Count)
    30.                 Current = 0;
    31.  
    32.             ParticleSystem1.Stop();
    33.             ParticleSystem1.transform.position = transform.position + Locations[Current];
    34.             ParticleSystem1.Play();
    35.         }
    36.     }
    37. }
    38.