Call GameObject::OnEnable()

Hello

I am trying to call a GameObject’s OnEnable() method but I am getting the compile error:

Type UnityEngine.GameObject' does not contain a definition for OnEnable’ and no extension method OnEnable' of type UnityEngine.GameObject’ could be found (are you missing a using directive or an assembly reference?)

I thought all GameObject’s had the methods OnEnable() and OnDisable()? Am I wrong? Is the method private?

public  bool managerEnabled {
	get {
		return managerEnabled;
	}
	set {
		managerEnabled = value;
		if(value)
			this.gameObject.OnEnable(); // compile error here
		else this.gameObject.OnDisable();
	}
}

OnEnable is not a part of GameObject. Methods like those are called via SendMessage. To achieve the same effect, you may want to do something like:

this.gameObject.SendMessage("OnEnable");

which call every OnEnable on every attached script on “this”.