What happened to GameObject.Enabled ?

Am i going mad? I’m trying to set the Enabled property on a gameobject, and its throwing an error

Line 33.
The error is: “UnityEngine.GameObject does not contain a definition for “Enabled””… etc

All i’m trying to do is programatically turn off the checkbox in the corner of a gameobject. I’ve done this a thousand times before. i don’t see whats wrong here

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;

[System.Serializable]
public class ActionButtonContent
{
    public int type;
    public Sprite icon;
    public Vector2 offset;
    public ActionButtonContent(int input)
    {
        type = input;
    }
}

public class ActionButton
{
    public  ActionButtonContent _content;
    public ActionButtonContent content
    {
        get
        {
            return _content;
        }
       
        set
        {
            if (value == null)
            {
                iconholder.sprite = null;
                button.Enabled = false;

            }
        }

    }
    public Image iconholder;
    public GameObject button;
    public int index;
    ActionPanel panel;


    public ActionButton(ActionPanel input, int style, int i)
    {
        panel = input;
        button = GameObject.Instantiate(GameManager.data.ButtonStyles[style]);
        button.transform.parent = panel.transform;
        index = i;
    }

    public void Remove()
    {
        panel.buttons.RemoveAt(index);
        GameObject.Destroy(button);
        index = -1;
        iconholder = null;
    }

}

public class ActionPanel : MonoBehaviour
{
    public SortedDictionary<int, ActionButtonContent> required = new SortedDictionary<int, ActionButtonContent>();
    public List<ActionButton> buttons = new List<ActionButton>();

   
    //What does this class do?

    //This class will maintain a dictionary of needed buttons.
        //This is unique, meaning that any given type of button appears zero or one times in the dictionary only. No duplicate buttons can ever exist.
    //Buttons will be registered or deregistered from this list, generally by other classes. Through wrapper functions in this class.
    //Whenever any content of that list changes,  this class will create or destroy buttons, and add them as its children.

    //Buttons added in this way will become visible in the UI
    //Whenever any of those buttons is clicked, it will trigger  a function in this class, sending back an int of the button.
    //This class will then broadcast an event indicating that that button was clicked. The event will include an integer that corresponds to the type of action which was assigned to the clicked button

    //Other classes will listen TO this class, for those events being broadcast, signaling that relevant buttons have been pressed.
    //They will then take action based upon the knowledge that the button has been clicked.
    //If relevant, those listening classes will then be responsible for deregistering buttonActions that are no longer needed.

    //The main classes which will interact with this are the selectionManager and OrderManager

    //Example:
        //Puppy picks up a toy.
        //Puppy broadcasts an event declaring that it has picked up OR dropped something.

        //OR

        //The selection list changes. Something is either added or removed (maybe all are deselected)


        //Ordermanager runs a function to check the ItemHolding status of all selected puppies.
        //If it finds that any of them are holding anything, it will register the Drop button here in this class.
        //This class creates the drop button as instructed

        //OR

        //if it finds that none are holding items. Then it wil UNregister the drop button here.
        //This class will check whether a drop button exists before deregistering it.


    //Next:
        //User clicks drop button.
        //Drop button calls a function in this class.
        //This class sends an event, with the drop button's ID as a parameter.

        //OrderManager, listening, hears this event.
        //It will run the checking function again, and dispatch a Drop order to all puppies which are holding an item
        //Ordermanager will then unregister the drop button from this class.


    //Registration:
        //Because the list of buttons will be a dictionary, lookup is simple.
        //When any register or deregister order comes in, we will first check if the requested dictionary element already exists.

    // Update is called once per frame
    void Update ()
    {
   
    }

    void RegisterButtonContent(int type)
    {
        if (!required.ContainsKey(type))
        {
            required[type] = ActionButtons.ab[type];
        }
    }

    void UnregisterButtonContent(int type)
    {
        if (required.ContainsKey(type))
        {
            required.Remove(type);
        }
    }

    void ManageButtonQuantity()
    {
        if (required.Count > buttons.Count)
        {
            //we need to create more buttons
            for (int i = 0; i < (required.Count - buttons.Count);i++)
            {
                ActionButton newbutton = new ActionButton(this, ActionButtons.STYLE_1, buttons.Count);
                buttons.Add(newbutton);
            }
        }
        else if (required.Count < buttons.Count)
        {
            //we need to cull some buttons
            for (int i = buttons.Count-1; i >=0; i--)
            {
                ActionButton newbutton = new ActionButton(this, ActionButtons.STYLE_1, buttons.Count);
                buttons.Add(newbutton);
            }
        }
    }

    void ClearButtons()
    {
        foreach (ActionButton button in buttons)
        {
            button.content = null;
        }
    }
}

Behaviours can be enabled or disabled, GameObjects cannot.
Typically, Behaviours come in the form of MonoBehaviour, which is what your scripts usually are. However, these behaviours are attached to a GameObject - they aren’t the GameObject in and of themselves.

Edit:
I stand corrected - I’m guessing this is what you’re looking for

My guess is that this enables/disables every Behaviour and the Renderer attached to a GameObject

GameObject’s have activeInHierarchy and activeSelf. (Mono)Behaviour’s have enabled.

The docs are your friend in situations like these.

2 Likes

There’s never been any GameObject.enabled, and there’s nothing that has an .Enabled property.

–Eric