How to automate removing non-MonoBehaviour derived scripts from a prefab
I'm in the process of updating a project from Unity 5.6 to 2020 LTS, which at this stage mostly involves updating character prefabs dependent upon Opsive plugins that have seen extensive updates in the years since 5.6. There are ~50 character prefabs so I'm trying to automate the process, but before Unity will allow saving of changes made to the prefabs, any missing or broken MonoBehaviours need to be removed.
I found threads on how to remove the missing MonoBehaviours via editor script (there's a handy function in the GameObjectUtility class that does it) but some of the MonoBehaviours that were attached no longer derive from MonoBehaviour, generating the following error:
'MeleeAttack' is missing the class attribute 'ExtensionOfNativeClass'! UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
These scripts also need to be removed before the prefab will save. I think I can detect them by attempting to cast to Component, then use DestroyImmediate to get rid of them if they won't cast. Unfortunately the only way I know of to get ahold of things attached to a GameObject is to use GetComponent and its variants, and those functions require you to specify the type of component to look for. The type has to be Component or one of its child classes. This means GetComponent can't return the non-MonoBehaviour derived scripts.
Does anyone know of an alternate way to get ahold of everything attached to a GameObject?
Thanks!
Your answer
Follow this Question
Related Questions
How to add a component from a Custom Editor object field to a Prefab ? 1 Answer
HideFlags not serializing, or possibly being reset? 0 Answers
Can I put the 'OnDrawGizmos' code in the CustomEditor? 1 Answer
How to make RequireComponent list possible options. 1 Answer
accessing a script using a variable with getComponent, then accessing a variable inside that script 1 Answer