Finding a GameObject with a given name in a generic list.

Hi there. I have a generic list ‘Nodes’ containing gameobjects. I would like to find an item in that list with a name equal to my string ActivatorArr. I intend to deactivate the object once I find it.

My current attempt (C#) is:

				TileAct = Nodes.Find(obj.name == ActivatorArr);
				if (TileAct != null)
					TileAct.SetActive (true);

but that top line incorrect of course. How would one phrase a search for a named obj within a .Find?

Consider using a lambda expression for your first line.

TileAct = Nodes.Find( x => x.name == ActivatorArr);

This is a convenient way of saying “for every item X, check if the name matches ActivatorArr”, and it’s used as a predicate to retrieve the first item that fits the conditions.

This of course assumes that ActivatorArr is a string, because you seem to be comparing the name to it.