using UnityEngine; using UnityEditor; using System.Collections.Generic; using System.Linq; using VRM; public class RemoveInvalidVRMSpringBones : EditorWindow { [SerializeField] private GameObject destinationPrefab; //[MenuItem("Tools/Remove Invalid VRM Spring Bones")] private static void ShowWindow() { GetWindow("Remove Invalid VRM Spring Bones").Show(); } private void OnGUI() { EditorGUILayout.LabelField("Remove Invalid VRM Spring Bones", EditorStyles.boldLabel); destinationPrefab = (GameObject)EditorGUILayout.ObjectField("Destination Prefab", destinationPrefab, typeof(GameObject), true); if (GUILayout.Button("Remove Invalid Bones")) { if (destinationPrefab == null) { EditorUtility.DisplayDialog("Error", "Destination Prefab must be set.", "OK"); return; } RemoveInvalidBones(); } } private void RemoveInvalidBones() { var springBones = destinationPrefab.GetComponentsInChildren(true).ToList(); foreach (var bone in springBones) { // Check if any of the root bones or collider groups are null (which indicates a missing reference) if (bone.RootBones.Any(rb => rb == null) || bone.ColliderGroups.Any(cg => cg == null)) { DestroyImmediate(bone); } } Debug.Log("Invalid VRM Spring Bones have been removed."); } }