GetComponent returning null.

I’ve been working on a simulator styled game and a big part of it is picking up objects in a Half Life similar style. In order to make sure that an object is intended to pick up and get more info such as rotationX, rotationY, rotationZ, etc I’ve attatched a script called Pickupable to the object and check for that here in my pickupItem method.
I work in a team so sharing files has caused some corruption issues and this script I’ve been working on disappeared. Thankfully I had a back up, but the back up is returning null every time it GetComponent for Pickupable. 2 weeks ago, I had virtually the same code, and this has NEVER been an issue. Each object that has been intended to be picked up does indeed have a Pickupable script attached. I’ve checked for most simple stuff like that. Any help would be very appreciated.

void pickupItem()
	{
		Vector3 fwd = mainCamera.transform.TransformDirection (Vector3.forward);
		RaycastHit hit; 
		if (Input.GetKeyDown (KeyCode.E)) 
		{
			if (Physics.Raycast (mainCamera.transform.position, fwd, out hit))
			{
				GameObject objectInView = hit.transform.gameObject; //Gets object directly forward of main camera (player).
				Rigidbody rig = objectInView.transform.GetComponent<Rigidbody>();
				Pickupable pick = objectInView.transform.GetComponent<Pickupable>();
				pickO = pick;

				if(pick == null) print ("pick is null"); // Prints for debugging purproses.
				print("rig is " + rig);

				if(pick && rig && hit.distance < 5)
				{
					carrying = true;
					carried = objectInView;
				}
				else
					Debug.Log ("Pickupable is null OR distance is too far.");

			}
		}
		
		if (pickO) {
			x = pickO.rotateX;
			y = pickO.rotateY;
			z = pickO.rotateZ;
		}
		
	}

Just to clarify, when I try to get a reference (correct word?) to Pickupable, it returns null even though I haven’t changed anything in this method for weeks and it worked just fine before. I don’t get any actual NullReferenceExceptions but I would if I didn’t have the proper if statements.

Since you are using a raycast to get the hit object, you probably want to filter that raycast using layers. You could add ONLY items that have a Pickupable component to that layer.
Then when you hit the item with the filtered raycast, you can be confident it will have the component you are looking for.

If you had ONLY pickupable objects in your scene you wouldn’t need this. I suspect you have added objects that do NOT have this component, since the last time this code was working.