Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Bone Renderer Setup Protected in Editor Utils as of 2020.2

Discussion in 'Animation Rigging' started by GoldFireStudios, Feb 1, 2021.

  1. GoldFireStudios

    GoldFireStudios

    Joined:
    Nov 21, 2018
    Posts:
    160
    I've been calling `AnimationRiggingEditorUtils.BoneRendererSetup()` from an editor script to init a bone renderer on an rigged object added to the scene, which is really helpful for visualization. However, when upgrading to 2020.2 from 20201., I now get an error that this method is protected and can't be called. Is there some other way I can achieve this still without having to manually go to the menu and select that option from the list for every object I add to the scene with my editor tool?
     
  2. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    I am also using the bonerenderer, I think it should be made part of unity itself, cause it's very useful.
    I add the component at runtime and init it like this:

    Code (CSharp):
    1.  if (ShowBones)
    2.                 {
    3.                     UnityEngine.Animations.Rigging.BoneRenderer boneRenderer = ReferenceSkin.rootBone.gameObject.AddComponent<UnityEngine.Animations.Rigging.BoneRenderer>();
    4.                     boneRenderer.transforms = SkinnedMeshCombiner.GetAllHumanoidBones(animator);
    5.                 }  
    6.  
    7.  
    SkinnedMeshCombiner is my custom class to combine skinnedmeshes. Below the code of the method above.
    Code (CSharp):
    1.  
    2.  
    3. public static Transform[] GetAllHumanoidBones(Animator _animator)
    4.     {
    5.  
    6.         if (_animator == null) return null;
    7.         List<Transform> HumanBones=new List<Transform>();
    8.         foreach (HumanBodyBones bone in Enum.GetValues(typeof(HumanBodyBones)))
    9.         {
    10.             if (bone != HumanBodyBones.LastBone)
    11.             {
    12.            
    13.                     HumanBones.Add(_animator.GetBoneTransform(bone));
    14.  
    15.              
    16.            
    17.             }
    18.        
    19.         }
    20.         return HumanBones.ToArray();
    21.     }
    Not using 2020.2 yet, so don't know if the code above works anymore.