mob-sakai / ParticleEffectForUGUI

Render particle effect in UnityUI(uGUI). Maskable, sortable, and no extra Camera/RenderTexture/Canvas.
MIT License
4.42k stars 625 forks source link

Particles spawn too close to the camera #319

Closed MihaMarkovi closed 4 months ago

MihaMarkovi commented 4 months ago

Unity version: 2021.2.20f1 Package version: 4.9.0

Hello! I have encountered the problem with particles spawning too close to the camera as shown on the picture below. In this example, Auto Scaling mode is set to "UI Particle". particles

When I set Auto Scaling Mode to "None", that seems to fix the issue, but particles are now way too large. particles2

Am I doing something wrong? Thanks in advance.

mob-sakai commented 4 months ago

Thank you for your reporting! Could you please attach a minimal project (included Assets, Packages and ProjectSettings directories) that reproduces the issue?

repos

MihaMarkovi commented 4 months ago

ParticlesBug.zip

mob-sakai commented 4 months ago

@MihaMarkovi In haste, here is the workaround:

// Assets/Games/Test/Scripts/LuckyChip.cs (178)
// _particles2DCircle.Play();
// _particles2DStars.Play();
var uip = GetComponentInChildren<UIParticle>();
uip.enabled = false;
uip.enabled = true;
_particles2DCircle.Simulate(0);
_particles2DStars.Simulate(0);
await MoveChipToPosition(_initialPosition, playPlaceAnimation);
...
mob-sakai commented 4 months ago

fixed.webm

MihaMarkovi commented 4 months ago

Thanks for fix @mob-sakai ! I have implemented your solution, but Simulate method resets particles when you call it multiple times, which I don't want, so I replaced it with Play. When using Play method, particles are still drawn in front of the camera, but no I at least dont see them, so that works fine for me. Do you by any chance know when this will be fixed?

mob-sakai commented 4 months ago

Unfortunately, a fundamental fix is hard to find. A better solution is to control emissions with ParticleSystem.emission.enabled=true/false instead of ParticleSystem.Play()/Stop().

ParticleSystem.main.looping = true;
ParticleSystem.main.playOnAwake = true;
ParticleSystem.emmision.enabled = false;

// _particles2DCircle.Play();
// _particles2DStars.Play();
GetComponentInChildren<UIParticle>().StartEmission();
await MoveChipToPosition(_initialPosition, playPlaceAnimation);
GetComponentInChildren<UIParticle>().StopEmission();
// _particles2DCircle.Stop();
// _particles2DStars.Stop();
...