if (comp.GetType().GetCustomAttributes(typeof(RequireComponent), false).Length > 0)
{
bool contains = false;
foreach (RequireComponent required in comp.GetType().GetCustomAttributes(typeof(RequireComponent), false))
{
if (required.m_Type0 != null && !requiredComponents.Contains(required.m_Type0)) requiredComponents.Add(required.m_Type0);
if (required.m_Type1 != null && !requiredComponents.Contains(required.m_Type1)) requiredComponents.Add(required.m_Type1);
if (required.m_Type2 != null && !requiredComponents.Contains(required.m_Type2)) requiredComponents.Add(required.m_Type2);
if(((required.m_Type0 != null && required.m_Type0 != typeof(Transform))|| (required.m_Type1 != null && required.m_Type1 != typeof(Transform))|| required.m_Type2 != null && required.m_Type2 != typeof(Transform)) && !contains)
{
contains = true;
requirees += comp.GetType() + "
";
}
}
}
this function is adding components that are required to a list and it works perfectly for custom scripts with the [RequireComponent(Type)] however it does not work for any of the built-in components that require other components. For example the Fixed Joint component requires a Rigidbody. I thought that perhaps it wasn’t working because maybe their scripts do not contain a [RequireComponent(Type)] but instead were requiring it somehow else, but, I recently got ahold of Unity’s Editor Source code in which at the top of the script it reads [RequireComponent(typeof(Rigidbody))]. Does anyone know how I can fix it not working for unity components?