Activating a deactivated gameObject?

I’m trying to disable and activate a child gameObject based on the parents condition. So far i can disable the object but i cant re-enable it. I just get the NullRefrenceException. Does Unity no longer reconize a gameObject that has been disabled at runtime?

function ShieldUpDown(){
	
   if (ShieldsEnabled == true){
		if (ShieldsUp == false){
			if (Shields > 0){
				ShieldsUp = true;
				transform.Find("/Fighter/Shield").gameObject.active = true;
			}
		}
		else
		if (Shields <=0){
			if (ShieldsUp == true){
				ShieldsUp = false;
				transform.Find("/Fighter/Shield").gameObject.active = false;
			}
		}
	}
	else
	ShieldsUp = false;

The end result I’m really just trying to deactivate the collider component.

You have to cache the reference to the de-activated object beforehand, because Find doesn’t return inactive objects.

Something like

var shieldObj : GameObject;
function Start(){
  shieldObj = transform.Find("/Fighter/Shield").gameObject;
}

plus your code listed above should work.

Ahh ok thanks for that :slight_smile: