Question by
caos23121987 · Feb 12, 2018 at 07:39 AM ·
namegameobject.findfind-gameobject
GameObject.Find(CaseInsensetive) ?
Good Morning. Is there a way to search for the name of a GameObject using CaseInsenetive?
Comment
Best Answer
Answer by Hellium · Feb 12, 2018 at 09:46 AM
You can define an extension method to implement a Find function with a predicate to check whether or not a given child is the one you are looking for.
using UnityEngine;
public static class TransformExtensions
{
public static Transform Find(this Transform transform, System.Predicate<Transform> predicate)
{
int childCount = transform.childCount;
for (int childIndex = 0; childIndex < childCount; ++childIndex)
{
Transform child = transform.GetChild(childIndex);
if (predicate(child))
return child;
else
child.Find(predicate);
}
return null;
}
}
Then, use it as follow:
void Start()
{
Transform myTransform = transform.Find( child => child.name.ToLower().Equals( "name of the transform" ) ;
}
However, this method does not support the slashes in the path, like in the normal Find method.
Your answer
![](https://koobas.hobune.stream/wayback/20220612152448im_/https://answers.unity.com/themes/thub/images/avi.jpg)