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:

  1. 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.
  2. 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
  3. 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.

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:

  1. 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

  2. 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

Encountered the bug and had no idea how to fix it. Activate/Deactivate all children fixed it right away

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?

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>();