Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question 2D bones, Reset bind pose not working

Discussion in '2D' started by jonjons, Jan 17, 2023.

  1. jonjons

    jonjons

    Joined:
    Oct 13, 2016
    Posts:
    41
    Is there a way to restore the original bones position. Has in Skinning Editor.
    According to the manual ( reset bind pose ) does this... but its not working

    ""Reset Bind Pose The button resets the GameObject Transforms assigned in the Bones entry to the bind pose value setup for the Sprite in the Skinning Editor module.""

     
    Last edited: Jan 17, 2023
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    Honestly, I can't figure out any kind of consistent behavior for this. It appears as though the bones need to be in a hierarchy for their positions to be reset, but then sometimes certain bones simply won't reset in my tests.

    The best solution I've come up with is to not touch bones outside of animation or play mode. If you really need to reset their positions, you can click on the parent "01head1" and then "Overrides" in the inspector. You can then reset any changes made to the prefab instance.

    You can also delete the prefab instance and add a new one.

    Sorry I can't be of more help, but this is perplexed me for quite some time and I just work around it.
     
    jonjons likes this.
  3. jonjons

    jonjons

    Joined:
    Oct 13, 2016
    Posts:
    41
    Thanks for answering, ill take a look at prefab. Iam not sure about this, was thinking maybe the best option would be to type on the script the original x, y, position of the bones... It just sounded like a so easy option even the sprite editor can do, if the Reset Bind Pose button would work, it would make the code less confusing.
     
  4. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    I was actually curious how difficult this would be to accomplish, and it turns out it's super easy to do. I'm starting to think that the "Reset Bind Pose" button is bugged now. You can submit a bug report if you want.

    I tried making a bone reset script for fun and this is what I came up with:
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3.  
    4. [ExecuteAlways]
    5. public class ResetBones : MonoBehaviour
    6. {
    7.     [SerializeField] string boneNameContains = "bone";
    8.     [SerializeField] bool saveBones = false;
    9.     [SerializeField] bool resetBones = false;
    10.  
    11.     [SerializeField] List<Transform> bones = new List<Transform>();
    12.     [SerializeField] List<Vector3> bonePositions = new List<Vector3>();
    13.     [SerializeField] List<Quaternion> boneRotations = new List<Quaternion>();
    14.  
    15.     void Update()
    16.     {
    17.         if (Application.isPlaying) { return; }
    18.  
    19.         if (saveBones)
    20.         {
    21.             bones = new List<Transform>();
    22.             bonePositions = new List<Vector3>();
    23.             boneRotations = new List<Quaternion>();
    24.  
    25.             foreach (Transform bone in GetComponentsInChildren<Transform>())
    26.             {
    27.                 if (bone.name.Contains(boneNameContains))
    28.                 {
    29.                     bones.Add(bone);
    30.                     bonePositions.Add(bone.transform.localPosition);
    31.                     boneRotations.Add(bone.transform.localRotation);
    32.                 }
    33.             }
    34.  
    35.             Debug.Log("Bone positions and rotations are saved.");
    36.  
    37.             saveBones = false;
    38.         }
    39.  
    40.         if (resetBones)
    41.         {
    42.             foreach (Transform bone in bones)
    43.             {
    44.                 bone.localPosition = bonePositions[bones.IndexOf(bone)];
    45.                 bone.localRotation = boneRotations[bones.IndexOf(bone)];
    46.             }
    47.  
    48.             Debug.Log("Bone positions and rotations have been reset.");
    49.  
    50.             resetBones = false;
    51.         }
    52.     }
    53. }
    You can use this if you like, but you'd have to rename your bones to have something in common (like the word "bone" for example). The way the script works is when you tick the "saveBones" bool, it loops through all child objects and checks if their name contains a specific string (the "boneNameContains" variable), and then saves their positions and rotations in a list. You can then tick the "resetBones" variable to loop through all of the bones and set their positions/rotations back to the saved values. The script goes on the parent object. The lists are serialized in the inspector for reference.

    I just made this for fun and thought I'd share it. Obviously, if you're a competent coder you don't have to use any of this haha.
     
    jonjons likes this.
  5. jonjons

    jonjons

    Joined:
    Oct 13, 2016
    Posts:
    41
    hey, thanks

    I renamed the bones right before starting to try and reseting their position ( bnUP1, bnUP2, bnUP3 // bnMD1,bnMD2,bnMD3 // bnDN1, bnDN2, bnDN3 );

    Iam actually doing everything in script... making a timer / reseting it to zero, and changing the position of the bones ( like an animation ).

    Has you can imagine the code gets blunted very quickly... ( The image has 9 bones )... **now add more images and that's 9 bones times nº of images...:cool: **

    It would be easier on the code to access the reset bind pose Button in script to return the bones to their original position.. But iam ok in creating new variable to contain the original bones (x, y), if theres no other way to do it...
     
  6. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    Sorry, I'm a bit confused. Are you using my script? The reason I said to rename the bones is because the script finds the bones via a string. If your bones all share the string "bn" then you would need to set the "boneNameContains" variable to "bn." You do have to be careful about this though, as if any other objects contain the string "bn" then the script will also target those objects. I find using a string is the easiest way to find bones because they are objects that only contain a transform component, which makes them difficult to pinpoint.

    I'm not quite sure what you mean by this. The number of images shouldn't affect anything, as you just need to reset the position of the bones.

    If you are using my script, it's really just as simple as attaching is to the parent, changing the "boneNameContains" variable to "bn" and then ticking the "saveBones" bool. You can then tick "resetBones" at any time to reset the bone positions. It's not the best script ever, but it works as far as my testing went.
     
  7. jonjons

    jonjons

    Joined:
    Oct 13, 2016
    Posts:
    41
    thanks, iam using the image with bones on a player, along with other images that also contain bones