• RuntimesUnity
  • Bones not returning to where they should be in Unity?

Hey Everyone,

I am running into a problem with some of my bones when playtesting in Unity.
When I rigged and animated my player character, it was facing the right. This might have something to do with what is happening? I doubt it, but I don't know.

When I first imported my Mechanim and started making a controller; I just threw a big boxcollider2d on it so that I could worry about other things. I have now gotten around to trying to make shape specific colliders that follow the bones. When I enabled the setting that allows me to see my bones and interact with specific ones to add colliders to them; I noticed something odd was happening to the front foot. When I am moving to the left and stop, the bones on my characters front foot break. All pivot roughly 180 degrees at the ankle so that the bottom of the foot faces to the sky. The bone on the ankle isn't transforming anywhere, but I don't know how to tell if it is rotating or if the bones on the actual foot are moving. The only thing that follows them is the collider. The images of the foot stay where they are supposed to be- planted on the ground. I cannot figure out what would cause something like this. It doesn't 'happen when I try it moving to the right, nor are any other groups of bones messing up. The back foot is working just fine.

I am using IKs. I have no idea if that information would be relevant to the issue.
I am also using this in a little experimental scene for testing out Playmaker. I have written 0 code. I don't think Playmaker is the issue either.

I'm sure its something dumb that I have done and can't spot on my own. I'm very new to game dev as a whole.

Here are some screenshots of what's going on.

  • Misaki ответили на это сообщение.
    Related Discussions
    ...

    It seems like the issue you're experiencing with the bones not returning to their correct positions in Unity could be related to the IK constraints or the setup of your skeleton. From the context provided, similar issues have been observed when the IK is not applied correctly, possibly due to the Mix setting being at 0 or other configuration issues. Additionally, if the IK target is a child of a bone that is being flipped or transformed, it might cause unexpected behavior. You should check the IK settings, ensure that the Mix is set correctly, and verify that the IK target is not improperly nested within the hierarchy. Also, consider reviewing the bone hierarchy and constraints to ensure they are set up correctly.

    • Изменено

    scarywilko I am not sure this is the cause, it just occurred to me as a possibility, but in SkeletonMecanim all keys of animated items must be keyed in the first frame of the animation, otherwise the pose may not be updated properly. So it could be that the lack of IK constraint keys in the first frame is causing the IK not to be applied and the bone orientation to be incorrect. If you haven't added the IK Constraints key yet, could you try adding it and see if that solves the problem? Note also that when using SkeletonMecanim, it is basically better not to use Animation cleanup.

    • scarywilko ответили на это сообщение.

      Misaki I assumed that you mean the keys in the animations themselves? I checked and they seemed to be keyed there, but I went ahead and redid it just to be safe. It behaves the same after importing the updated version. I am not using cleanup and I even moved the mix settings within Unity as Spinebot suggested. The other point that it made about being a child of a bone being flipped or transformed might also be the issue, but I don't quite understand what the fix would be or why that foot is the only one breaking. I made both legs and feet the same way. The whole character is being flipped in unity on the x-axis when I move left though.

      • Misaki ответили на это сообщение.

        scarywilko I see, thank you for confirming that. So could you tell us how you flip your skeleton?
        Since you mentioned that you have written 0 code, you probably didn't flip your skeleton the way you changed Skeleton's ScaleX, so could you try to see if that would work if you have not tried it yet? Here is a very simple example script:

        using System.Collections;
        using System.Collections.Generic;
        using UnityEngine;
        using Spine.Unity;
        
        public class SkeletonFlipping : MonoBehaviour
        {
            private SkeletonMecanim skeletonMecanim;
        
            private Animator m_Animator = null;
        
            void Start()
            {
                skeletonMecanim = GetComponent<SkeletonMecanim>();
                m_Animator = GetComponent<Animator>();
            }
        
            void Update()
            {
                if(m_Animator.GetBool("FlipX") == false){
                    skeletonMecanim.Skeleton.ScaleX = 1;
                }else if(m_Animator.GetBool("FlipX") == true){
                    skeletonMecanim.Skeleton.ScaleX = -1;
                }
            }
        }

        This example script assumes that the script is attached to the skeleton's GameObject and that the Animator of the skeleton has a bool named "FlipX". This should allow you to test the flipping as demonstrated in the following video:

        • scarywilko ответили на это сообщение.

          Misaki Here is how I have done everything:

          This is my movement setup.

          This is how I make it flip

          And this one is how I have set the scale of my character. I made it way too big, but I didn't bother changing it for now as I knew it could be scaled down and I have to redesign it later anyway. This whole thing is just my way of trying to test things and learn how to use them.

          • Misaki ответили на это сообщение.

            scarywilko Thank you for the additional explanation. I'm still not sure why that wouldn't work, since it looks like all you're doing is changing the GameObject's ScaleX, but I think it's not a bad idea to try inverting the Skeleton's ScaleX. If you haven't tried it yet, please do so.

            Regarding the scale of your skeleton asset, I guess the reason you might think you made your skeleton too large is because the scale is set to 0.01, but actually that is the default and normal value. If you use Spine in the standard way, your export will be 1 pixel for 1 unit, where in Unity a unit is typically set to 1 meter. So a scale of 0.01 results in 100 pixels being equal to 1 Unity unit (meter).

            • scarywilko ответили на это сообщение.

              Misaki Oof! I may have told you wrong then, although I'm almost positive that I changed it to 0.01 myself. He was MASSIVE compared to the rest of the things in the scene on import. I am still quite ignorant when it comes to not only spine, but unity and coding as well; so I could have told you wrong on how I scaled him down in size. I'm like 99% sure that I did it from there though. I think it was set to 1 before I changed it? Also, if it's not too much trouble, can I ask what the difference is when you say to invert it opposed to changing it? I am not sure what that means. I really appreciate all the help you have provided!

              • Misaki ответили на это сообщение.

                Technically invert is 1/x. 🤓 Likely by "invert" Misaki meant that 1 becomes -1. Using -1 scaleX or scaleY will flip your skeleton.

                scarywilko The scale set when the skeleton data asset is created can be changed to a default value in the following section in Preferences - Spine, so if this is set to 1, the scale of your skeleton data asset should have been set to 1 immediately after import:

                There is no connection between the scale value of the skeleton data asset and the issue of your skeleton not inverting correctly. However, since you attached a screenshot of the skeleton asset scale value, I just wanted to let you know that it is normal for it to be set to 0.01. You might want to re-read the SkeletonDataAsset section of the documentation: https://esotericsoftware.com/spine-unity-assets#Skeleton-Data-Asset