- Home /
GetComponentsInChildren not working on iphone
I'm having problems using C# GetComponentsInChildren on iphone.
I've tried this:
BoxCollider[] carColliders = this.GetComponentsInChildren(typeof(BoxCollider)) as BoxCollider[];
But it is not assigning, the value of carColliders gets null.
So I've tried this:
Component[] carColliders = this.GetComponentsInChildren(typeof(BoxCollider));
That way it assigns, but I can not use it as a BoxCollider I get this error when i try to use a casting:
Assets / Scripts / General / AI.cs (282.49): error CS1503: Argument 1: Can not convert type UnityEngine.Component 'to
UnityEngine.Collider'
Any ideas?
Thanks in advance for any help
Answer by Mike 3 · May 25, 2010 at 02:54 PM
You can use Array.ConvertAll to create the correct type of array:
Component[] before = GetComponentsInChildren(typeof(BoxCollider));
BoxCollider[] after = Array.ConvertAll<Component, BoxCollider >(before, delegate(Component c) { return (BoxCollider)c; });
It works but only if we use .NET 2.1 with unity iphone 1.6 Thanks
yupyup, otherwise you just need to put up with casting each item seperately, which isn't so fun :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613024317im_/https://answers.unity.com/themes/thub/images/avi.jpg)