Fix errors using GetComponents with an interface#1
Fix errors using GetComponents with an interface#1shayded-exe wants to merge 2 commits intoprime31:masterfrom shayded-exe:master
Conversation
Now uses the non-generic version of GetComponents then casts back to the proper type.
|
Actually this doesn't quite work right. The GetComponents are returning null. Will update with a real fix. |
|
Aaaand there we go. The cast is now done per-element using Array.ConvertAll. The old method would just cast the whole thing. |
|
I've extracted out the extra code around I wont put it in the pull request, but you can use it if you wish :) public static T[] GetInterfaceComponents<T>(this Component parent) where T : class
{
return System.Array.ConvertAll(parent.GetComponents(typeof(T)), c => c as T);
} |
|
I am not sure I am following this. GetComponents works fine with interfaces as of Unity 4.6 From the release notes: |
|
Strange, your normal code didn't compile for me because of GetComponents, so that's why I did this. I'm using 4.6.7. |
Now uses the non-generic version of GetComponents then casts back to the
proper type.