On a humanoid avatar, when the VRC Avatar Descriptor has an empty
baseAnimationLayers
list but
customizeAnimationLayers
is false, then in
InitAnimLayer
a NullReferenceException is thrown from
element.FindPropertyRelative("type").enumValueIndex = (int)type;
This is caused by
EnforceAnimLayerSetup
assuming there is at least one layer, and calling
InitAnimLayer
with index=1;
list.InsertArrayElementAtIndex(1)
then fails, and so the subsequent
GetArrayElementAtIndex
also returns null.
This issue was encountered by a user of Vroid's Xavatar, and reported to me as a potential Modular Avatar bug (MA invokes this code to normalize animator layers, but this also happens just by opening the inspector normally).
Stack traces:
Retrieving array element that was out of bounds
UnityEditor.SerializedProperty:InsertArrayElementAtIndex (int)
AvatarDescriptorEditor3:InitAnimLayer (UnityEditor.SerializedProperty,VRC.SDK3.Avatars.Components.VRCAvatarDescriptor/AnimLayerType,bool,int) (at ./Packages/com.vrchat.avatars/Editor/VRCSDK/SDK3A/Components3/VRCAvatarDescriptorEditor3AnimLayerInit.cs:128)
AvatarDescriptorEditor3:EnforceAnimLayerSetup (bool) (at ./Packages/com.vrchat.avatars/Editor/VRCSDK/SDK3A/Components3/VRCAvatarDescriptorEditor3AnimLayerInit.cs:166)
AvatarDescriptorEditor3:OnEnable () (at ./Packages/com.vrchat.avatars/Editor/VRCSDK/SDK3A/Components3/VRCAvatarDescriptorEditor3.cs:41)
Retrieving array element that was out of bounds
UnityEditor.SerializedProperty:GetArrayElementAtIndex (int)
AvatarDescriptorEditor3:InitAnimLayer (UnityEditor.SerializedProperty,VRC.SDK3.Avatars.Components.VRCAvatarDescriptor/AnimLayerType,bool,int) (at ./Packages/com.vrchat.avatars/Editor/VRCSDK/SDK3A/Components3/VRCAvatarDescriptorEditor3AnimLayerInit.cs:129)
AvatarDescriptorEditor3:EnforceAnimLayerSetup (bool) (at ./Packages/com.vrchat.avatars/Editor/VRCSDK/SDK3A/Components3/VRCAvatarDescriptorEditor3AnimLayerInit.cs:166)
AvatarDescriptorEditor3:OnEnable () (at ./Packages/com.vrchat.avatars/Editor/VRCSDK/SDK3A/Components3/VRCAvatarDescriptorEditor3.cs:41)
NullReferenceException: Object reference not set to an instance of an object
AvatarDescriptorEditor3.InitAnimLayer (UnityEditor.SerializedProperty list, VRC.SDK3.Avatars.Components.VRCAvatarDescriptor+AnimLayerType type, System.Boolean isDefault, System.Int32 index) (at ./Packages/com.vrchat.avatars/Editor/VRCSDK/SDK3A/Components3/VRCAvatarDescriptorEditor3AnimLayerInit.cs:131)
AvatarDescriptorEditor3.EnforceAnimLayerSetup (System.Boolean isOnEnable) (at ./Packages/com.vrchat.avatars/Editor/VRCSDK/SDK3A/Components3/VRCAvatarDescriptorEditor3AnimLayerInit.cs:166)
AvatarDescriptorEditor3.OnEnable () (at ./Packages/com.vrchat.avatars/Editor/VRCSDK/SDK3A/Components3/VRCAvatarDescriptorEditor3.cs:41)