GameObject.FindGameObjectsWithTag cannot have same tag?

// Function: Searches for the correct object to apply it's "item" on
	GameObject F_Search (string pS_target, string pS_tag)
	{
		// Search: Finding something from an array of objects with reference to their tag(s)
		foreach(GameObject obj in GameObject.FindGameObjectsWithTag(pS_tag))
		{
			// Condition: If the object found and it's name matches the target
			if (obj.name == pS_target)
			{
				Debug.Log("Searched successfully for: " + obj.name);
				return obj;
			}
			else
			{
				Debug.Log("Warning: GameObject of target named: " + pS_target + " cannot be found");
				return null;
			}
		}
		return null;
	}

Hello Forums,

I am trying to find a particular unique named object from a common tag. I have “Cube1” and “Cube2” with the same tag: “CubeObjects” and the above is my code. Basically, Cube1 cannot be detected while Cube2 can be, when I changed Cube1’s tag to another exclusive tag, it is detected. So how exactly does FindGameObjectsWithTag works? Maybe somebody can help me out. Thanks in advance.

Note: Just for information, I am parsing the name and tag of the objects via XML while the objects are already in the Hierarchy.

Research Dolphin.

Based on a quick look over your code, the first thing I noticed is that you return from the function after checking the first game object in the returned array, regardless of how many objects there are. So in effect, you’re only ever checking the first (relative to the order in which the objects are returned) of all game objects with the specified tag.