Finding GameObject without using the full name

Hi, I have problem with this one:


finds only GameObjects with this specific name. I have to find GameObjects with with a name that contains a a fragment of string, for example:


finds Car1, Car2 etc.
Any ideas? :slight_smile:

If you are not using your tags for anything else, then the easiest solution would be to tag all of your cars with a β€˜Car’ tag. Then you would not need a string search. You could then use GameObject.FindGameObjectsWithTag() to get all the cars. If you really need the substring search, you could use GameObject.FindObjectsOfType() to get a list of all the game objects. Then you could cycle through the list using any string comparison that makes sense to find your objects. Note that both FindGameObjectsWithTag() and FindObjectsOfType() only return active game objects and that FindObjectsOfType() is slow.

As a way of creating a more compact search if you need to cycle through all the game objects, take a look at LinQ: