After SkinnedMesh Component's sharedmesh, animator can't find bones at once. i also assign new bones.

SkinnedMeshRenderer skinnedMesh;
Animator animator;
SkinnedMeshRenderer protoTypeSkinnedMesh;
Animator protoTypeAnimator;
Transform bones;
GameObject bonesObject;
Transform rootBone;

    animator = obj.GetComponent<Animator>();
    skinnedMesh = obj.GetComponent<SkinnedMeshRenderer>();
    
    protoTypeSkinnedMesh = skinMeshList[id];
    
    skinnedMesh.sharedMesh = protoTypeSkinnedMesh.sharedMesh;
    skinnedMesh.sharedMaterial = protoTypeSkinnedMesh.sharedMaterial;

    protoTypeAnimator = animators[id];
    animator.runtimeAnimatorController = protoTypeAnimator.runtimeAnimatorController;
    animator.avatar = protoTypeAnimator.avatar;

    Destroy(obj.transform.GetChild(0).gameObject);     //hips, for bones

    bonesObject = Instantiate(bonesObjs[id]);
    bones = bonesObject.transform.GetComponentsInChildren<Transform>();
   
    bonesObject.transform.SetParent(obj.transform);
    rootBone = bonesObject.GetComponent<Transform>();

    skinnedMesh.bones = bones;
    skinnedMesh.rootBone = rootBone;

after run this code, the object’s Animator Component show warnings
Transform ‘Head’ has been deleted
Transform ‘Hand_L’ has been deleted
Transform ‘Head_R’ has been deleted

but these are the bones before they change.
i do ‘skinnedMesh.bones = bones;’
And during runtime, if I change something in the Animator component in the inspector window, warning goes away and it works as I intended.

i was try animator.Rebind() but it is still…

It seems like the issue might be related to the order in which the bones are being assigned to the SkinnedMeshRenderer. Try modifying your code as follows:

bonesObject.transform.SetParent(skinnedMesh.transform); // Set parent to skinned mesh
bones = bonesObject.transform.GetComponentsInChildren<Transform>();

skinnedMesh.bones = bones;
skinnedMesh.rootBone = bonesObject.transform;

By setting the parent of the bonesObject to the skinnedMesh transform, the bone hierarchy should be updated correctly and the warning messages should go away.

no. i do it, it is still has same problem. when I change something in the Animator component in the inspector window, warning goes away and it works as I intended. i want to run the code that when i change something in the Animator component in the inspector window