- Home /
ParticleSystem position bug on mobile devices?
I have a completely weird situation:
I am using ortho camera and ParticleSystems. On mobile devices they started to behave strangely (appearing at wrong positions), so I narrowed the problem down to this:
I spawn numerous instances of the same particle system prefab, and some of them (1 out of 20 or so) simply spawns on the wrong place in the view.
The ones that spawned wrong have CORRECT transform.position and transform.localPosition - same as the ones that show in correct positions and different from what I see on screen
I would be certain that I missed something very basic (even though I checked 50 times) BUT this occurs ONLY on mobile devices; both iOS and Android and NEVER on PC or Web build
Correct transform positions make this VERY hard to debug, I have no clue what to look for and where.
I'm using Unity 4
Has anyone else encountered such strange behavior?
Any help or just directing me towards where to start look would be awesome.
Answer by sstublic · Jan 16, 2013 at 03:35 PM
For whoever is experiencing similar issues, it seems I've stumbled upon a workaround.
So the problem was I was using ParticleSystem prefabs (play on awake = false) and reusing the same object multiple times (with spawning system from Cartoon fx pack - this system is not source of any issue, I've tried it all without it). Bugs I've encountered:
Particle systems which had LOCAL simulation space have been PAUSING emission and particle animation while not visible in camera (????), so if u started the system, moved it off camera and return 5 secs later it would continue where it stopped 5 secs ago - this problem manifested on both mobile builds and pc/web builds
Particle systems/some of their PS children occasionally appeared at wrong position. It seems somewhere between Vector3.zero and intented transform.position (thanks to Jean Moreno from cartoon fx pack for pointing this pattern out) - this problem manifested ONLY in mobile builds
Workaround I've found to work for me is this: Whenever instantiating a new prefab or reusing existing one, EXPLICITLY deactive ParticleSystem and ALL of its children. For some reason I had to iterate through children, SetActive only on parent won't suffice. After this I set new position and in the same manner activate both parent and its children. When I start the ParticleSystem with Play after this, PROBLEM IS GONE.
If you omit deactivate/activate steps, aforementioned two bugs reappear.
All this seems pretty confusing to me and my fix is like a bad band aid, but it works for me and nothing else does, so I thought to post it. Maybe it can help someone else.
Cheers!
p.s. using Unity 4
$$anonymous$$any thanks for your solution. This bug was driving me nuts.
I'm experiencing the same bug. Thanks for the workaround. Did you submit a bug report to Unity? They really need to fix this.
BU$$anonymous$$P for this thread! Had a very similar problem recently was driving me crazy needs to be fixed!
http://answers.unity3d.com/questions/536529/how-to-get-a-particlesystem-to-play-when-you-cant.html
Wondering what you use to activate/deactivate it though?
$$anonymous$$y particles have no children and this is still occurring with Play() and Stop(). $$anonymous$$aybe I should try Pause() ins$$anonymous$$d of stop?
I also have tried a bunch of other stuff nothing seemed to work, some of them were even more buggy than Play() not sure what's the deal with Unity particles...
particleObject.particleSystem.enableEmission = false; particleObject.renderer.enabled = false;
Tried pretty much everything else in the past particleCount() clearParticles(), always been quite the pain especially when using for first time.
$$anonymous$$anaged to get everything to work eventually except for one new system when the starting point of particleSystem is not on camera and using Start() and Stop()
Edit:
$$anonymous$$ finally got it working thanks to your advice! :)
Funny how it's always the last thing I try for problems like this... things that make no sense in Unity is a common occurrence.
So just using something like this to enable and disable works although probably excessive using Play() and Stop() due to this bug...
Here's example in case helps anyone:
public GameObject healthParticleBeam;
public ParticleSystem healthParticleSystem;
void HealthPotionBeamEnableFunction()
{
healthParticleBeam.SetActive(true);
healthParticleSystem.Play();
}
public void HealthPotionBeamDisableFunction()
{
healthParticleBeam.SetActive(false);
healthParticleSystem.Clear();
healthParticleSystem.Stop();
}
I encountered the same problem. Thanks guys. SetActive saved me finally... I really want to know why it works... ;-(
Answer by agouin · Feb 26, 2013 at 04:47 PM
Encountered the bug and had no idea how to fix it. Activate/Deactivate all children fixed it right away
Answer by LuminaryTech · Apr 05, 2015 at 03:31 PM
Solution for anybody needing it for a particle system with children, this solved it for me and should be the most efficient way since it avoids a foreach loop and is only built this way on mobile.
/// <summary>
/// The muzzle flash that occurs when firing
/// </summary>
public ParticleSystem muzzleFlash;
#if UNITY_IOS || UNITY_ANDROID
/// <summary>
/// The muzzle flash systems.
/// </summary>
private ParticleSystem[] muzzleFlashSystems;
#endif
// Use this for initialization
void Awake () {
muzzleFlashSystems = GetComponentsInChildren<ParticleSystem>();
}
//Inside method somewhere...
#if UNITY_IOS || UNITY_ANDROID
//Patch for mobile, the particle system would appear at random locations without this reset, unsure why? Unity bug?
for (int j = 0; j < muzzleFlashSystems.Length; j++) {
muzzleFlashSystems[j].gameObject.SetActive(false);
muzzleFlashSystems[j].gameObject.SetActive(true);
}
#endif
//Play the muzzle flash
muzzleFlash.Play();
Has this been reported to Unity?
Answer by Yodzilla · Jan 26, 2016 at 12:26 PM
As of 5.0.2 this bug is still a problem and it's not limited to mobile. Here's the ugly code that fixes it...for some reason.
GameObject mobSpawnParticle = ((GameObject)GameObject.Instantiate(Resources.Load("Prefabs/Levels/MobSpawnParticle")));
foreach (ParticleSystem ps in mobSpawnParticle.GetComponentsInChildren<ParticleSystem>(true)) {
ps.gameObject.SetActive(false);
}
mobSpawnParticle.transform.SetParent(gameObject.transform);
mobSpawnParticle.transform.localPosition = new Vector3(0, 0, 0);
foreach (ParticleSystem ps in mobSpawnParticle.GetComponentsInChildren<ParticleSystem>(true)) {
ps.gameObject.SetActive(true);
}
spawnParticle = mobSpawnParticle.GetComponent<ParticleSystem>();
Your answer
![](https://koobas.hobune.stream/wayback/20220613091004im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to change the size of a particle 0 Answers
ParticleSystem.randomSeed doesn't work? 1 Answer
Shuriken particle System - change velocity by trigger 0 Answers
Shuriken Texture Sheet Animation How to choose Random Row Between 2 Constants? 0 Answers
Emulate Editor's Particle Scrubbing Functionality in Game 1 Answer