About the pit of Animation parameter missing

Some time ago, the game encountered a problem of crashing on the real machine. There was no printing, no loading error, and it was really a headache to find the problem.

Channel: PPTV

Problem: The clip in an Animation component on the model prefab is missing.

Phenomenon: Loading resources crashes.

Guess: Our project is dependent packaging, the prefab is packaged separately as A, and all the clips it depends on are packaged as a package B. When prefab A is loaded, it is found that the animation clip that it depends on has not been loaded, and it will load B package, but there is no such animation clip in B package. No error is reported because package A and dependent package B are indeed loaded successfully.

Question: Only one channel will flash back, and other platforms can run normally. Could it be that PPTV’s SDK processing loading causes the crash.

Today, the clip missing method of checking Animation is added at the place where resources are loaded. It is found that there is no API to call directly, so compare GetClipCount() with the number of all animation clips to compare whether any animation clips are missing.

The animation component in Unity gets the number of current animation clips: GetClipCount()

Add a method to calculate the number of all current animation clips GetClipCount(Animation ani). If it is on the editor, you can directly call the API: AnimationUtility.GetAnimationClips.

  public void CheckAnimationClip(GameObject go,string assetPath)
        {
            if (!UsedAssetBundle && FResourceCommon.IsEditor())
            {
                var m_Animations = go.transform.GetComponents<Animation>();
                for (int i = 0; i < m_Animations.Length; i++)
                {
                    var m_Animation = m_Animations[i];
                    //var _temp = AnimationUtility.GetAnimationClips(m_Animation.gameObject);
                    int _clipCount = m_Animation.GetClipCount();
                    if (GetClipCount(m_Animation) != _clipCount)
                    {
                        Log.Error("检查动画组件是否missing:" + assetPath + ",GameObject名称:" + m_Animation.name);
                    }
                }
            }
        }

        private int GetClipCount(Animation ani)
        {
            int _count = 0;
            foreach (AnimationState item in ani)
            {
                _count++;
            }
            return _count;
        }

Compare whether the two numbers are consistent, if not, it means that the animation clip is lost.

Guess you like

Origin blog.csdn.net/qq_33461689/article/details/122671841