Search Unity

First particle does not respect particle systems' forward if that system has moved and rotated

Discussion in 'General Graphics' started by xVergilx, Sep 2, 2019.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    I've got a weird bug:
    I'm using single particle system to emit particles from multiple points. And if that particle system has moved, first emitted particle does not respect particle systems forward alignment correctly (even if the X rotation is the same in both cases). See gif:
    GIF.gif

    Is this a bug, or am I missing something?
    Here's a code to test this:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(ParticleSystem))]
    4. public class ParticleEmitTest : MonoBehaviour {
    5.     [SerializeField]
    6.     private Transform _pointA = default;
    7.  
    8.     [SerializeField]
    9.     private Transform _pointB = default;
    10.  
    11.     [SerializeField]
    12.     private ParticleSystem _ps = default;
    13.  
    14.     [SerializeField]
    15.     private Transform _transform = default;
    16.  
    17.     private void Update() {
    18.         if (Input.GetMouseButtonDown(0)) {
    19.             EmitFrom(_pointA);
    20.         }
    21.  
    22.         if (Input.GetMouseButtonDown(1)) {
    23.             EmitFrom(_pointB);
    24.         }
    25.     }
    26.  
    27.     private void EmitFrom(Transform point) {
    28.         _transform.SetPositionAndRotation(point.position, point.rotation);
    29.  
    30.         ParticleSystem.EmitParams emitParams = new ParticleSystem.EmitParams();
    31.         emitParams.applyShapeToPosition = true;
    32.         emitParams.position = point.position;
    33.  
    34.         _ps.Emit(emitParams, 1);
    35.     }
    36.  
    37. #if UNITY_EDITOR
    38.     protected virtual void OnValidate() {
    39.         _ps = GetComponent<ParticleSystem>();
    40.         _transform = transform;
    41.     }
    42. #endif
    43. }
    44.  
    Just in case, submitted repro - case 1181119.
     
    Last edited: Sep 2, 2019
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I suspect it’s a real bug.

    As a workaround (and because it’s more efficient) Set the Transform in the shape module instead :)
     
    karl_jones and xVergilx like this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Yes, that does seems to work.
    Here's a workaround (if anyone needs it):
    Code (CSharp):
    1.  
    2.     private void EmitFrom(Transform point) {
    3.         _transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
    4.      
    5.         ParticleSystem.ShapeModule shapeModule = _ps.shape;
    6.         Vector3 position = point.position;
    7.      
    8.         shapeModule.position = position;
    9.         shapeModule.rotation = point.rotation.eulerAngles;
    10.  
    11.         ParticleSystem.EmitParams emitParams = new ParticleSystem.EmitParams();
    12.         emitParams.applyShapeToPosition = true;
    13.  
    14.         _ps.Emit(emitParams, 1);
    15.     }
    16.  
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Great! And thanks for submitting the bug report :)
     
    karl_jones and xVergilx like this.