How to obtain a gameObject from an List with the name?

Hey Guys! I’m a bit stuck here. I’ve a List through which I’m looping and checking to see whether the object I’ve send through the argument is active or not. If not I’m activating it.

But what I want is to check whether the gameObject with the same name as I’m sending to it is active or not. Is there a way I can do this or not.

Here is my code:
public GameObject activateObstacle(int id, string name){

		for (int i = 0; i < obstaclePool[id].Count; i++) 
		{
			if(!obstaclePool[id]*.activeInHierarchy)*
  •  	{*
    

_ obstaclePool[id].SetActive(true);_

_ string spawnedObstacleName = obstaclePool[id].gameObject.name;_

* Debug.Log("spawned obstacle name is " + spawnedObstacleName);*

_ return obstaclePool[id];
* }
}
}*

I want to check whether spawnedObstacleName is similar to the name parameter that I’m sending. And If it is same then do all the stuff like checking whether it is active or not and then activating it.
Please Help. Thank you._

if ( name == spawnedObstacleName ) {
// stuff
}

That said, don’t use object names. It’s extremely unreliable because someone will make a typo at some point and it will be extremely hard to track down why that’s causing an error.

Use custom components with an identifier (like index) if you have to, but names are a
last resort.

In your case you want to store the obstacles in a list so you can just send the index and simply not care what the name is.