Here’s a gif of the problem I’m having:
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?
Here’s a gif of the problem I’m having:
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?
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?
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.
@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.
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.
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
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.
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.
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?
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.
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.
public class Follower : MonoBehaviour
{
#region Fields
[SerializeField] private Transform follow;
[Header("Position")]
[SerializeField] private bool followPosition = true;
[SerializeField] private float positionSmoothing = -1f;
[Header("Rotation")]
[SerializeField] private bool followRotation = true;
[SerializeField] private float rotationSmoothing = -1f;
private Vector3 offsetPosition;
private Quaternion offsetRotation;
#endregion
#region Methods
private void Start()
{
SetFollow(follow);
}
private void Update()
{
if (!follow) return;
if (followPosition)
{
transform.position = (positionSmoothing == -1f) ?
transform.position = follow.position - offsetPosition :
Vector3.Lerp(transform.position, follow.position - offsetPosition, Time.deltaTime * positionSmoothing);
}
if (followRotation)
{
transform.rotation = (rotationSmoothing == -1f) ?
Quaternion.Euler(follow.rotation.eulerAngles - offsetRotation.eulerAngles) :
Quaternion.Slerp(transform.rotation, Quaternion.Euler(follow.rotation.eulerAngles - offsetRotation.eulerAngles), Time.deltaTime * rotationSmoothing);
}
}
public void SetFollow(Transform follow)
{
this.follow = follow;
offsetPosition = follow.position - transform.position;
offsetRotation = Quaternion.Euler(follow.rotation.eulerAngles - transform.rotation.eulerAngles);
}
#endregion
}
Is this something that will be looked into though? I can’t imagine using a Follower is the desired solution?
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.
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…
Haha. Yes this is what we recommend and that’s coming from the Particles lead(me!).
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…
Sorry Karl, did you respond to the topic? I got an email update, but maybe you deleted the answer…
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.
I found a solution to this by using the UnityEngine.LowLevel API to add a custom update function where I run the IK solving between the animation update and particle system update. It might work for you with some adjustments: