Animator is not playing an AnimatorComponent (Error on Unity)

This error is for an avatar. I got it after i figured out some other errors (I’m really new at this stuff) I’m not sure what you would need, but the code is down below. If you have questions I’ll do my very best to answer. Thank you <3

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Dynamics.PhysBone;
using VRC.Dynamics;
using VRC.SDKBase.Validation;

namespace VRC.SDK3.Avatars
{
    public static class AvatarDynamicsSetup
    {
        [RuntimeInitializeOnLoadMethod]
        private static void RuntimeInit()
        {
            //Triggers Manager
            if (ContactManager.Inst == null)
            {
                var obj = new GameObject("TriggerManager");
                UnityEngine.Object.DontDestroyOnLoad(obj);
                ContactManager.Inst = obj.AddComponent<ContactManager>();
            }

            //Triggers
            ContactBase.OnInitialize = Trigger_OnInitialize;

            //PhysBone Manager
            if (PhysBoneManager.Inst == null)
            {
                var obj = new GameObject("PhysBoneManager");
                UnityEngine.Object.DontDestroyOnLoad(obj);

                PhysBoneManager.Inst = obj.AddComponent<PhysBoneManager>();
                PhysBoneManager.Inst.IsSDK = true;
                PhysBoneManager.Inst.Init();
                obj.AddComponent<PhysBoneGrabHelper>();
            }
            VRCPhysBoneBase.OnInitialize = PhysBone_OnInitialize;
        }
        private static bool Trigger_OnInitialize(ContactBase trigger)
        {
            var receiver = trigger as ContactReceiver;
            if (receiver != null && !string.IsNullOrWhiteSpace(receiver.parameter))
            {
                var avatarDesc = receiver.GetComponentInParent<VRCAvatarDescriptor>();
                if (avatarDesc != null)
                {
                    var animator = avatarDesc.GetComponent<Animator>();
                    if (animator != null)
                    {
                        // called from SDK, so create SDK Param access
                        receiver.paramAccess = new AnimParameterAccessAvatarSDK(animator, receiver.parameter);
                    }
                }
            }

            return true;
        }
        private static void PhysBone_OnInitialize(VRCPhysBoneBase physBone)
        {
            if (!string.IsNullOrEmpty(physBone.parameter))
            {
                var avatarDesc = physBone.GetComponentInParent<VRCAvatarDescriptor>();
                if (avatarDesc != null)
                {
                    var animator = avatarDesc.GetComponent<Animator>();
                    if (animator != null)
                    {
                        physBone.param_IsGrabbed = new AnimParameterAccessAvatarSDK(animator, physBone.parameter + VRCPhysBoneBase.PARAM_ISGRABBED);
                        physBone.param_Angle = new AnimParameterAccessAvatarSDK(animator, physBone.parameter + VRCPhysBoneBase.PARAM_ANGLE);
                        physBone.param_Stretch = new AnimParameterAccessAvatarSDK(animator, physBone.parameter + VRCPhysBoneBase.PARAM_STRETCH);
                    }
                }
            }
        }

        [MenuItem("VRChat SDK/Utilities/Convert DynamicBones To PhysBones")]
        public static void ConvertSelectedToPhysBones()
        {
            List<GameObject> avatarObjs = new List<GameObject>();
            foreach (var obj in Selection.objects)
            {
                var gameObj = obj as GameObject;
                if (gameObj == null)
                    continue;

                var descriptor = gameObj.GetComponent<VRCAvatarDescriptor>();
                if (descriptor != null)
                {
                    avatarObjs.Add(gameObj);
                }
            }
            if (avatarObjs.Count == 0)
            {
                EditorUtility.DisplayDialog("Warning", "No avatars found.  Please select an avatar in the hierarchy window before using this feature.", "Okay");
            }
            else
            {
                ConvertDynamicBonesToPhysBones(avatarObjs);
            }
        }
        public static void ConvertDynamicBonesToPhysBones(IEnumerable<GameObject> avatarObjs)
        {
            if (!EditorUtility.DisplayDialog("Warning", "This operation will remove all DynamicBone components and replace them with PhysBone components on your avatar. This process attempts to match settings but the result may not appear to be the same. This is not reversible so please make a backup before continuing!", "Proceed", "Cancel"))
                return;

            foreach(var obj in avatarObjs)
                ConvertToPhysBones(obj);
        }
        static void ConvertToPhysBones(GameObject avatarObj)
        {
            try
            {
                //Find types
                var TypeDynamicBone = ValidationUtils.GetTypeFromName("DynamicBone");
                var TypeDynamicBoneCollider = ValidationUtils.GetTypeFromName("DynamicBoneCollider");
                if (TypeDynamicBone == null || TypeDynamicBoneCollider == null)
                {
                    EditorUtility.DisplayDialog("Error", "DynamicBone not found in the project.", "Okay");
                    return;
                }

                //Get Data
                var animator = avatarObj.GetComponent<Animator>();
                var dbcList = avatarObj.GetComponentsInChildren(TypeDynamicBoneCollider, true);
                var dbList = avatarObj.GetComponentsInChildren(TypeDynamicBone, true);

                //Convert Colliders
                var dbcDataList = new List<PhysBoneMigration.DynamicBoneColliderData>();
                foreach (var dbc in dbcList)
                {
                    var data = new PhysBoneMigration.DynamicBoneColliderData();
                    data.gameObject = dbc.gameObject;
                    data.bound = (PhysBoneMigration.DynamicBoneColliderData.Bound)(int)TypeDynamicBoneCollider.GetField("m_Bound").GetValue(dbc);
                    data.direction = (PhysBoneMigration.DynamicBoneColliderData.Direction)(int)TypeDynamicBoneCollider.GetField("m_Direction").GetValue(dbc);
                    data.radius = (float)TypeDynamicBoneCollider.GetField("m_Radius").GetValue(dbc);
                    data.height = (float)TypeDynamicBoneCollider.GetField("m_Height").GetValue(dbc);
                    data.center = (Vector3)TypeDynamicBoneCollider.GetField("m_Center").GetValue(dbc);

                    dbcDataList.Add(data);
                }

                //Convert to PhysBones
                var dbDataList = new List<PhysBoneMigration.DynamicBoneData>();
                foreach (var db in dbList)
                {
                    var data = new PhysBoneMigration.DynamicBoneData();
                    data.enabled = ((MonoBehaviour)db).enabled;
                    data.gameObject = db.gameObject;
                    data.root = (Transform)TypeDynamicBone.GetField("m_Root").GetValue(db);
                    data.exclusions = (List<Transform>)TypeDynamicBone.GetField("m_Exclusions").GetValue(db);
                    data.endLength = (float)TypeDynamicBone.GetField("m_EndLength").GetValue(db);
                    data.endOffset = (Vector3)TypeDynamicBone.GetField("m_EndOffset").GetValue(db);
                    data.elasticity = (float)TypeDynamicBone.GetField("m_Elasticity").GetValue(db);
                    data.elasticityDistrib = (AnimationCurve)TypeDynamicBone.GetField("m_ElasticityDistrib").GetValue(db);
                    data.damping = (float)TypeDynamicBone.GetField("m_Damping").GetValue(db);
                    data.dampingDistrib = (AnimationCurve)TypeDynamicBone.GetField("m_DampingDistrib").GetValue(db);
                    data.inert = (float)TypeDynamicBone.GetField("m_Inert").GetValue(db);
                    data.inertDistrib = (AnimationCurve)TypeDynamicBone.GetField("m_InertDistrib").GetValue(db);
                    data.stiffness = (float)TypeDynamicBone.GetField("m_Stiffness").GetValue(db);
                    data.stiffnessDistrib = (AnimationCurve)TypeDynamicBone.GetField("m_StiffnessDistrib").GetValue(db);
                    data.radius = (float)TypeDynamicBone.GetField("m_Radius").GetValue(db);
                    data.radiusDistrib = (AnimationCurve)TypeDynamicBone.GetField("m_RadiusDistrib").GetValue(db);
                    data.freezeAxis = (PhysBoneMigration.DynamicBoneData.FreezeAxis)(int)TypeDynamicBone.GetField("m_FreezeAxis").GetValue(db);
                    data.gravity = (Vector3)TypeDynamicBone.GetField("m_Gravity").GetValue(db);
                    data.force = (Vector3)TypeDynamicBone.GetField("m_Force").GetValue(db);

                    //Colliders
                    var dbColliders = (IList)TypeDynamicBone.GetField("m_Colliders").GetValue(db);
                    if (dbColliders != null && dbColliders.Count > 0)
                    {
                        var colliders = new List<PhysBoneMigration.DynamicBoneColliderData>(dbColliders.Count);
                        foreach (var dbc in dbColliders)
                        {
                            var index = System.Array.IndexOf(dbcList, (Component)dbc);
                            if (index >= 0)
                                colliders.Add(dbcDataList[index]);
                        }
                        data.colliders = colliders;
                    }

                    dbDataList.Add(data);
                }

                //Convert to PhysBones
                PhysBoneMigration.Convert(animator, dbDataList, dbcDataList);

                //Cleanup
                foreach (var dbc in dbcList)
                    Component.DestroyImmediate(dbc);
                foreach (var db in dbList)
                    Component.DestroyImmediate(db);
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
                EditorUtility.DisplayDialog("Error", "Encountered critical error while attempting to this operation.", "Okay");
            }
        }
    }
}

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

You may edit your post above.

1 Like