I am developing a 2D game in Unity and encountered a problem that I cannot fix no matter what I do.
I have a player character (a .psb file separated into layers with bones attached inside of unity's skinning editor) with an animator attached. In the animator, there are two layers – one base layer and one "lantern" layer (called so because it is responsible for blending between the regular animations and those specifically designed for holding a lantern). Both layers are set to override, the lantern layer is synced, and its weight is controlled by script.
My character always starts gradually flying up when a second layer exists, regardless of its settings, weight, or state motions. If I delete the layer, all problems disappear. If I disable "apply root motion" on the animator, the problem disappears as well, but sadly I need it enabled. However, no animation actually modifies the character's transform, only the rotation of the bones. And now it becomes fun: when I run an animation that does modify the player's position, after it ends, the player no longer flies up.
All topics I found concerning this are about 3D rigs that have significantly more settings than my 2D animation clips (only 3 options here... sigh), and usually solve this issue by baking into pose Y (or something amongst those lines) or setting "Foot IK" to true. Nevertheless, all setting combinations both on the clips and on the animator fail to resolve the issue ("Foot IK" settings on the animator states also don't change anything, so I set them to disabled). The only 3 ways to stop my player from indefinitely flying upwards are: deleting the second layer, playing an animation that modifies the player's position once, or disabling root motion.
Also, no script modifies the player's y-coordinate in such a way that could make this issue (I disabled them all one by one and it didn't make a difference).
I know it is a very vague issue but I wouldn't have posted here if I could solve it on my own. I have not attached any screenshots or code as I am left under the impression that it is more of a theoretical problem... also no setting combinations on the animator or the clips was able to change anything, so... :/ Needless to say, if anyone deems it would be helpful, I will gladly do it.
Thank you in advance!
Best regards, Coccho
Upgrading from the default render pipeline to Universal Render Pipeline OR updating Unity to version 2019.3.2f1 solved the issue.
EDIT: Not true! Problem occurred again some time afterwards. The issue is caused by (perhaps internal?) updates in the animator; for example, when manually changing a state's speed in the animator editor whilst in play mode, or when changing animator state settings in code (changing the animator speed itself seems not to cause any issues). I never managed to locate the concrete reason behind this or fix it, but I have found a workaround that is good enough to practically make the issue non-existent: