Holstering/drawing a weapon

Hi, I want to draw and holster a sword but it’s going wrong. Position and rotation are getting messed up.

Sorry am away from my own code now but I will just explain.

In Blender I put bones where I want the weapons to be. I can click at those placeholder bones in Unity and they’re in the right spot. My plan is to

  1. parent to holster/handweapon bone
  2. set to parents position
  3. set to parents rotation

But even 2. seems to fail, they appear with a position offset, rotation fails too.

My bones in Blender are unparented.

Anyone got any ideas that I could try tomorrow or a way in which it definitely worked for you?

Thx

EDIT: Oh I should add that I do this while an animation is happening.

I could post you my scripts but they are all set up for my game requirements and which wont fit your game. So i am gonna try to explain it.
create a weapon script and add it to weapon. This script will contain stats of weapon like damage and range and also

public bool currentWeapon = false;
[Header("Armed-Positioning")]
public Transform armedHolder;
public Vector3 armedPosition;
public Vector3 armedRotation;

[Header("UnArmed-Positioning")]
public Transform unarmedHolder;
public Vector3 unarmedPosition;
public Vector3 unarmedRotation;

once you are done with it create a weaponHolder script which will get all those stats from weapon.

void EquipWeapon()
{

    if (currentWeapon != null)
    {
        GetCurrentWeaponProperties();

        currentWeapon.transform.SetParent(armedHolder);
        currentWeapon.transform.localPosition = armedPosition;
        Quaternion equipRot = Quaternion.Euler(armedRotation);
        currentWeapon.transform.localRotation = equipRot;
        currentWeapon.GetComponent<Rigidbody>().isKinematic = true;
        currentWeapon.GetComponent<Collider>().enabled = false;
        anim.SetInteger("Weapon", weapontype);
        IKisON = true;
    }
}
void HosterWeapon()
{
    if (currentWeapon != null)
    {
        currentWeapon.transform.SetParent(unarmedHolder);
        currentWeapon.transform.localPosition = unarmedPosition;
        Quaternion equipRot = Quaternion.Euler(unarmedRotation);
        currentWeapon.transform.localRotation = equipRot;
        IKisON = false;
        currentWeapon = null;
    }
    if (currentWeapon == null)
    {
        Debug.Log("No weapon");// Delete this.
        return;
    }
}

void GetCurrentWeaponProperties()
{
    if(currentWeapon == null)
    {
        return;
    }

    if (currentWeapon != null)
    {
        weaponManager WM = currentWeapon.GetComponent<weaponManager>();          
        armedHolder = WM.armedHolder;
        armedPosition = WM.armedPosition;
        armedRotation = WM.armedRotation;

        unarmedHolder = WM.unarmedHolder;
        unarmedPosition = WM.unarmedPosition;
        unarmedRotation = WM.unarmedRotation;
        weapontype = WM.weapontype;
        weaponDamage = WM.weaponDamage;

}

you have to create a list of weapons that you are gonna carry

public List<GameObject> weapons;
public int weaponIndex = 0;

and add another function to switch weapons when you press a switch weapon key
This part is important… you have to add 2 animation events which will run equipt and holster functions…

public void SwicthWeapon()
{
        if (weapons.Count > 0)
        {
             anim.SetTrigger("AnimationHolster");
            Debug.Log("Holstering");
            weaponIndex = weaponIndex + 1;
            if (weaponIndex == weapons.Count)
            {
                weaponIndex = 0;
            }
            currentWeapon = weapons[weaponIndex];
            GetCurrentWeaponProperties();

            anim.SetTrigger("AnimationEquipt");
            Debug.Log("Equipting");
        }
}

Dont forget to add 2 empty gameobjects to your player which will contain holster position and equipt position. They will be parent when you set them equipted or holstered.

As i told you even i send you the scripts they will make you confuesed thats why you better understand how it is done.
Just study the scripts. You basicly create a list which will contain weapons. All weapons have their own stats including positions and rotation. When you switch them you will get their stats information from weapon script and set them to your currents on weaponHolder script. Then use them as current ones. It is very simple way but it works. I hope it will help you.