SetActive() not working

SetActive(true) isn’t working on game Object “lostlife”. Though SetActive(false) works on it. I tried renderer.enabled, activeInHierarchy, active but still it aint working. Why? What should I do?

if(paddle.life == 1)
			{  
				GameObject life_2 = GameObject.Find("life2");
				GameObject lost = GameObject.Find("lostlife");
				life_2.SetActive(false);
				lost.gameObject.active = true;
				//lost.renderer.enabled = true;(why null ref)
				//lost.renderer.enabled = true;
				//lost.activeInHierarchy = true;

				//after some secs disable the message
				//Destroy(lost, 4);
			}

GameObjects that are disabled cannot be found with GameObject.Find(). You’re getting a NullReferenceExeption because the variable was never set in the first place due to the mix up…

You have to store the object in a variable to access it.

Is it set to inactive by default? GameObject.Find() can’t find inactive objects (as far as I know). If not, is it being set to false anywhere else in the game? If not, Debug.Log everything relevant, something may be wrong.

If the GameObject is disabled at startup (starts disabled rather than gets made disabled) then you cannot Find() the GameObject at runtime. One options is to set it a public variable and assign it in the inspector, another is to Instantiate a prefab of the object as it is required.