I’ve been digging through the forums for this for hours, it’s totally time to just ask lol:
All the component grabbing functions unity provides require a Type parameter, which makes them useless when you want to get back every component attached to the gO.
My reasons for doing this are to be able to get all components out of an object that are a subclass of a particular type. I can’t find any snippets on doing this anywhere in particular. Here’s what I have:
public static ArrayList GetComponentsOfType<T>(GameObject o) where T : class {
Component[] objs = o.GetComponents(); // if only, if only i could just leave this parameter list blank
ArrayList goodObjs = new ArrayList();
T com;
for (int i = 0; i < objs.Length; ++i) {
com = objs[i] as T;
if (com != null) {
goodObjs.Add(com);
}
}
return goodObjs;
}
Is there a gap in my knowledge, or am I screwed?
Cheers