Search Unity

Bug Unity3D particle system not updating with character rotation

Discussion in 'General Graphics' started by daniel_lochner, May 19, 2020.

  1. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    171
    Here's a gif of the problem I'm having:
    problem.gif

    The flame is set as a child of the flamethrower's muzzle and I have it set to simulate in world space, however it seems it doesn't update with the bone rotation of the player? Is this a bug?
     
  2. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I don't think there are such bugs.
    Did you parent a sphere to the bone of your muzzle to check & see if it follows the muzzle mesh?
     
    karl_jones likes this.
  3. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    171
    Thank you for responding! I really do appreciate it!

    I found a thread here where the op was having the exact same issue for the exact same reason. His solution wasn't a solution however, but more a workaround... He highlighted that the particle system follows the root bone transform, but not any children, which is exactly what I'm seeing as well...

    Here is another gif where I've attached a sphere to the muzzle.
    problem2.gif
     
    richardkettlewell likes this.
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    @daniel_lochner
    That's odd because I tried in my own game and I can't reproduce the issue.
    It's in world simulation too.

    https://i.imgur.com/wIQyUEY.gifv

    I've had weird things happen when the scale of the character/rig is not 1. You could check that out.

    You could also try and see if it works with Parent Constraint, although that's just a wild shot but it might give us more information.
     
    daniel_lochner likes this.
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Hi,
    Please file a bug report so we can look into it.

    I have seen this issue happen in the past. It was caused by changes being applied in LateUpdate which is ran after the Particle system update. If you are doing something in LateUpdate then try moving it to Update
     
    daniel_lochner and FeastSC2 like this.
  6. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    171
    Ah, that's exactly the issue then! I handle aiming in LateUpdate, but that's only because I need to rotate the spine of the player up and down... Where else could I handle this from?

    That's then also why you hadn't seen it in your game! The Particle System Update must be called after the Animator Update.
     
    FeastSC2 likes this.
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    We do the update just before LateUpdate so maybe you could do it inside the Animator section?
    https://docs.unity3d.com/Manual/ExecutionOrder.html
    Maybe one of the OnAnimatior methods or a coroutine.
     
    daniel_lochner likes this.
  8. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    171
    Hmm, I've tried OnAnimatorMove, OnAnimatorIK (with IK pass enabled) and various coroutine implementations, but LateUpdate seems to be the only method which successfully overwrites the animations?
     
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Hmm. Ok try making the particle system a separate game object and moving it during your late update instead of using parenting to the bone. The particles position will be 1 frame behind but this probably won't be noticeable for your effect.
     
  10. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    171
    That was the solution here, however I was hoping there was a more elegant one.

    I wrote a quick general-purpose Follower script which I've attached to the Fire, and then set it to follow the muzzle's transform.

    Code (CSharp):
    1. public class Follower : MonoBehaviour
    2. {
    3.     #region Fields
    4.     [SerializeField] private Transform follow;
    5.  
    6.     [Header("Position")]
    7.     [SerializeField] private bool followPosition = true;
    8.     [SerializeField] private float positionSmoothing = -1f;
    9.  
    10.     [Header("Rotation")]
    11.     [SerializeField] private bool followRotation = true;
    12.     [SerializeField] private float rotationSmoothing = -1f;
    13.  
    14.     private Vector3 offsetPosition;
    15.     private Quaternion offsetRotation;
    16.     #endregion
    17.  
    18.     #region Methods
    19.     private void Start()
    20.     {
    21.         SetFollow(follow);
    22.     }
    23.     private void Update()
    24.     {
    25.         if (!follow) return;
    26.  
    27.         if (followPosition)
    28.         {
    29.             transform.position = (positionSmoothing == -1f) ?
    30.                 transform.position = follow.position - offsetPosition :
    31.                 Vector3.Lerp(transform.position, follow.position - offsetPosition, Time.deltaTime * positionSmoothing);
    32.         }
    33.  
    34.         if (followRotation)
    35.         {
    36.             transform.rotation = (rotationSmoothing == -1f) ?
    37.                 Quaternion.Euler(follow.rotation.eulerAngles - offsetRotation.eulerAngles) :
    38.                 Quaternion.Slerp(transform.rotation, Quaternion.Euler(follow.rotation.eulerAngles - offsetRotation.eulerAngles), Time.deltaTime * rotationSmoothing);
    39.         }
    40.     }
    41.  
    42.     public void SetFollow(Transform follow)
    43.     {
    44.         this.follow = follow;
    45.  
    46.         offsetPosition = follow.position - transform.position;
    47.         offsetRotation = Quaternion.Euler(follow.rotation.eulerAngles - transform.rotation.eulerAngles);
    48.     }
    49.     #endregion
    50. }
    Is this something that will be looked into though? I can't imagine using a Follower is the desired solution?
     
    Last edited: May 20, 2020
  11. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    No unfortunately we looked into it a few years ago and changing the update order was deemed too risky. It would potentially break a lot of people's projects. It's not something that's easy to make configurable either.
    I believe there has been some work to allow configuration of the update loop so it may be possible as a general change but won't be something specific to particles.
     
  12. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    171
    Ah okay, thanks for your help. For the meantime can I get your official Unity stamp of approval that this is the way to go?

    I can then peacefully move on... :)
     
    karl_jones likes this.
  13. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Haha. Yes this is what we recommend and that's coming from the Particles lead(me!).
     
  14. REDvsGREEN

    REDvsGREEN

    Joined:
    Sep 8, 2019
    Posts:
    34
    Having the same issue today. One of the very popular asset store plugins called Final IK causes this by default. IE all final IK shooting games have this issue. I used your workaround Daniel, thanks!

    Might be worth fixing though..
     
  15. REDvsGREEN

    REDvsGREEN

    Joined:
    Sep 8, 2019
    Posts:
    34
    Sorry Karl, did you respond to the topic? I got an email update, but maybe you deleted the answer..
     
  16. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Oh yes I did but realized it was wrong. We landed a fix for Late Update in a recent patch but I don't think this will help with this issue, it was related to velocity.
     
    REDvsGREEN likes this.
  17. Emiliana_vt

    Emiliana_vt

    Joined:
    Apr 7, 2018
    Posts:
    13
    karl_jones likes this.