A replacement for Unity's GameObject.Find that supports CSS-like selectors and inactive GameObjects.
SuperFind allows you to find inactive GameObjects, use powerful selectors which make finding a GameObject much simpler and easy to maintain, and gives you a FindAll method to find all GameObjects that match your query.
Warning: SuperFind is approximately 10x slower than Unity's (already slow) GameObject.Find method. As with GameObject.Find, you should not use SuperFind in an update loop or any other performance sensitive code path.
- Download the latest .unitypackage in the releases archive
- Open your Unity project
- Double click on the downloaded package from step 1
- Import all the files into your project
GameObject found = SuperFind.Find(string selector);
Returns the GameObject that first matches the given selector string in the active scene, including inactive GameObjects. If no GameObjects match the selector string, null
is returned.
GameObject[] found = SuperFind.FindAll(string selector);
Returns all the GameObjects that match the given selector string in the active scene, including inactive GameObjects. If no GameObjects match the selector string, the returned list will be empty.
Each SuperFind method takes a selector string to target the GameObject(s) you're trying to find. Selector strings can combine any of the following features. Please note that GameObject's with spaces in their name are not currently supported.
- By name
Similarly to GameObject.Find
, pass the exact name of the GameObject.
Eg. SuperFind.Find("Child");
- By wildcard
Use *
instead of the GameObject's name to select a GameObject of any name.
Eg. SuperFind.FindAll("Parent *"); // Returns all the GameObjects under "Parent"
- By ascendant
Pass any number of ascendant's names (in order from furthest to closest) each followed by a space and finish with the name of the GameObject (plus a sibling index if wanted).
Eg. SuperFind.Find("Grandparent Child"); // Returns a Child with a GameObject named Grandparent as an ascendant
- By sibling index
Add a colon and the sibling index of the GameObject you want to find after the name of the GameObject.
Eg. SuperFind.Find("Enemy(Clone):3"); // Returns the 4th Enemy in a list of Enemy's
- By first sibling
Add :first
after the GameObject's name to find the first GameObject of that name in a list of GameObjects with that name.
Eg. SuperFind.Find("Enemy(Clone):first"); // Returns the first Enemy in a list of Enemy's
- By last sibling
Add :last
after the GameObject's name to find the last GameObject of that name in a list of GameObjects with that name.
Eg. SuperFind.Find("Enemy(Clone):last"); // Returns the last Enemy in a list of Enemy's
- By component
Add :
+ the component's name after the GameObject's name to find a GameObject with this Component (or MonoBehaviour)
Eg. SuperFind.FindAll("Tree:BoxCollider"); // Returns all Tree's with a BoxCollider
- By multiple flairs
Add a component selector and a sibling selector to combine selectors.
Eg. SuperFind.Find("Tree:BoxCollider:first"); // Returns the first Tree with a BoxCollider
See the SuperFind/Editor/
directory for a suite of unit tests. Run them in Unity by opening the Unity Test Runner (Window -> Test Runner) and clicking Run All
.
Find the SuperFind Inspector in Unity by going to Window -> SuperFindInspector
. This inspector can be used to test selectors in realtime.
- Exact name
SuperFind.Find("One");
- Exact name (with space)
SuperFind.Find("\"Colliders 2\"");
- Ascendant
SuperFind.FindAll("Three Child");
- Multiple ascendants
SuperFind.FindAll("Three Mid Child");
- Sibling index
SuperFind.Find("Child:3");
- First sibling
SuperFind.Find("Child:first");
- Last sibling
SuperFind.Find("Child:last");
- Acendants and sibling index
SuperFind.FindAll("Three Mid:first Child:3");
- Ancestor & Wildcard
SuperFind.FindAll("Mid *");
- Ancestor & Wildcard
SuperFind.FindAll("Three *");
- Component
SuperFind.Find("Child:BoxCollider");
- Wildcard & Component
SuperFind.FindAll("*:BoxCollider");
- Ancestor, Wildcard & Component
SuperFind.FindAll("Colliders *:BoxCollider");
- Find Ancestor, Wildcard, Component & Last Sibling
SuperFind.Find("Four *:BoxCollider:last");
- FindAll Ancestor, Wildcard, Component & Last Sibling
SuperFind.FindAll("Four *:BoxCollider:last");