diff --git a/Packages/src/Runtime/UIParticleRenderer.cs b/Packages/src/Runtime/UIParticleRenderer.cs index 6abfae10..045f997b 100644 --- a/Packages/src/Runtime/UIParticleRenderer.cs +++ b/Packages/src/Runtime/UIParticleRenderer.cs @@ -339,6 +339,7 @@ public void UpdateMesh(Camera bakeCamera) } else if (_renderer.CanBakeMesh()) { + _particleSystem.ValidateShape(); #if PS_BAKE_API_V2 _renderer.BakeMesh(s_CombineInstances[0].mesh, bakeCamera, ParticleSystemBakeMeshOptions.BakeRotationAndScale); diff --git a/Packages/src/Runtime/Utils.cs b/Packages/src/Runtime/Utils.cs index 36c64441..9c3b80aa 100644 --- a/Packages/src/Runtime/Utils.cs +++ b/Packages/src/Runtime/Utils.cs @@ -109,6 +109,29 @@ public static ParticleSystem.Particle[] GetParticleArray(int size) return s_TmpParticles; } + public static void ValidateShape(this ParticleSystem self) + { + var shape = self.shape; + if (shape.enabled && shape.alignToDirection) + { + if (Mathf.Approximately(shape.scale.x * shape.scale.y * shape.scale.z, 0)) + { + if (Mathf.Approximately(shape.scale.x, 0)) + { + shape.scale.Set(0.0001f, shape.scale.y, shape.scale.z); + } + else if (Mathf.Approximately(shape.scale.y, 0)) + { + shape.scale.Set(shape.scale.x, 0.0001f, shape.scale.z); + } + else if (Mathf.Approximately(shape.scale.z, 0)) + { + shape.scale.Set(shape.scale.x, shape.scale.y, 0.0001f); + } + } + } + } + public static bool CanBakeMesh(this ParticleSystemRenderer self) { // #69: Editor crashes when mesh is set to null when `ParticleSystem.RenderMode = Mesh`