Searching through hierarchy (428136)

can someone point me in the direction how to search game objects by keyword or partial name
i know about GameObject.Find, FindWithTag and GameObject.FindGameObjectsWithTag
but that works if you know the exact name or tag, what if i know the name partially?
how to handle this?

There is no wildcard facility in any of the Find functions but you may be able to generate the names using string concatentation. For example, suppose you have objects called “Waypoint1”, “Waypoint2”, etc. You could generate the names using code like:-

var waypointNumber: int;
var name = "Waypoint" + waypointNumber;

You would probably use this in a loop. Similarly, you might be able to store all the suffixes in an array if they are not numeric.

Why exactly do you need this ?
And why don’t the existing methods work in your case ?

i guess i was not clear enough…i made and edit box where i can type and search the objects in the scene.
i tried first with tags and it worked, it lists all objects that have tag that was typed, i used GameObject.FindGameObjectsWithTag
but now i want to type in the partial name of the object itself so it can give me all objects that have that string in their name.
i know it can be done, can someone help me with this?

One method might be getting all the objects using GameObject.FindObjectsOfType(GameObject) and going through them, checking if their name contains a certain string.

i am interested in that part, “checking if their name contains a certain string” i dont know how to do that

I think you can use the .Contains function on a string.

So if you’re iterating through the gameobject list, you can use the name of the object like so(psedo code)

if (gameObject.name.Contains(“Checkpoint”))
{
//do something
}

thanks a lot, that is what i was looking for

this is exactly what I need. I need to search through a list of objects and do a GameObject.Find(“partialName”). So there is no way to do that? Currently my script will search through the scene till if finds one with a certain name (there are multiple objects named the same). It does some stuff to it, changes it’s name, then searches to find another one. This all happens in a while loop. But because you can’t name something the same thing in the same scene in Maya. I need a wildcard for my .Find. Anyone have the magic answer? :slight_smile:

Jason