Can't find a component with GetComponent?

I’ve got a two-dimensional int array, and I’m trying to display all its values in space for the purpose of developing a pathfinding algorithm. But, I’m getting a compiler-time error.

Assets/Scripts/GridDataHolder.cs(141,92): error CS0246: The type or namespace name `PathingRoomText’ could not be found. Are you missing a using directive or an assembly reference?

Here’s my attempt, including detailed explanations:

public void RenderObstacles()
	{
		Vector3 obstacleCubeLocation = new Vector3(0, 0, 0);
		Vector3 obstacleLocationOnGrid = new Vector3(0, 0, 0);
		int w = distanceToObstacle.GetLength(0);
		int h = distanceToObstacle.GetLength(1);
		Quaternion genericQuat = new Quaternion(0,0,0,0);

		GameObject currentPathTextObj; //holds a copy of an empty object(called pathTextObj in this class' declarations) containing a TextMesh named 'PathingRoomText'
		TextMesh pathRoomTextMesh;
		
		for(int x = 0; x < w; x++)
		{
			for(int z = 0; z < h; z++)
			{
				obstacleLocationOnGrid.x = x; 
				obstacleLocationOnGrid.z = z;
					
				//values of 0 are unpathable and are represented currently by a generic object
				//whose size is dictated by the size of the plane they're being rendered on.
				//So don't worry about the next two lines of code.

				obstacleCubeLocation = GlobalVariables.Vector3Multiply(obstacleLocationOnGrid, obstacleScale);
				obstacleCubeLocation += GlobalVariables.PlaneOrigin - (GlobalVariables.PlaneSize / 2);
				
				if(distanceToObstacle[x,z] == 0)
					Instantiate(obstacleCube, obstacleCubeLocation, genericQuat);
					
				else
				{
					//the idea here is to instantiate each object in such a way that I can modify its value before moving on.
					//Specifically, I want to change the value displayed in its child TextMesh to equal the value
					//in the distanceToObstacle[x,z].

					currentPathTextObj = Instantiate(pathTextObj, obstacleCubeLocation, genericQuat) as GameObject;
					pathRoomTextMesh = currentPathTextObj.GetComponent<PathingRoomText>(); // <- This line is the problem.
					pathRoomTextMesh.text = string.Format("{0}", distanceToObstacle[x,z]);
				}
			}
		}
	}

Specifically, the line throwing the error is this:

pathRoomTextMesh = currentPathTextObj.GetComponent<PathingRoomText>();

I’m not wholly certain how GetComponent works, so I’ve tried it both using the component’s name and type. Using the type (TextMesh) instead of the component name throws a NullReferenceException.

Is PathingRooomText written in Javascript? Is so you likely will need to move it to Standard Assets.

http://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html

If you have an error during a compile time, GetComponent is not the one you should focus on.

The error indicates that PathingRoomText is not found in your solution. it may be caused by many ways :

  • the class does not exist => syntax error with the name of the class.
  • the class is not accessible in the current context => maybe you should add namespaces or add using directives to resolve it.
  • the class is not in the same assembly => as robertbu said it may happen if you did not write both classes in the same language.