this.gameObject null reference exception

Hello, I am having an issue with this.gameObject being null. I am unsure as to why it is saying that it does not exist. It isn’t an instantiated object. It is there in the editor. There aren’t any Destroy calls made on these objects.

Here is some of the code:

	public void UpdateCamera(){
		switch(controllingPlayer){
		case playerSlot.AI:
			break;
			
		case playerSlot.One:
			gameCameraScript.SetPlayer(1,this.gameObject);
			break;
			
		case playerSlot.Two:
			gameCameraScript.SetPlayer(2,this.gameObject);
			break;
			
		case playerSlot.Three:
			gameCameraScript.SetPlayer(3,this.gameObject);
			break;
			
		case playerSlot.Four:
			gameCameraScript.SetPlayer(4,this.gameObject);
			break;
			
		default:
			Debug.Log("Something broke in camera.");
			break;	
		}
	}

The error occurs for any of the “this.gameObject” references.

and,

This is the SetPlayer method being called here:

	public void SetPlayer(int _playerNumber,GameObject _playerObject){
		switch(_playerNumber){
		case 1:
			playerOne = _playerObject;
			break;
			
		case 2:
			playerTwo = _playerObject;
			break;
			
		case 3:
			playerThree = _playerObject;
			break;
			
		case 4:
			playerFour = _playerObject;
			break;
			
		default:
			break;
		}
	}

Does anyone know why this may be happening now? And hasn’t since 6/26.

Ok, so i went to lunch and when I returned this is no longer an issue. It just “works” again. No code changes, perhaps this is a bug in this version of unity?

Can’t you just use gameObject?

Okay, So I know that this question is years old, but I’m leaving my answer here just in case someone else stumbles across the same issue like I did.

Debug.Log("This gameObject is: " + this.gameObject); // <= this works
ship.SendMessage("AddShipComponent", this.gameObject); // <= this doesn't

I kept getting null reference errors on the line with the send message, despite the debug log line printing out what I would expect it to. After a couple days of pulling my hair out, I finally moved the script in question to execute after default time in the scrip execution order. After doing so, everything worked as expected.