Quick help

I get this error in this script and I dont understand why??? or how to solve it.

Error:
ArgumentException: GetComponent requires that the requested component ‘GameObject’ derives from MonoBehaviour or Component or is an interface.
UnityEngine.GameObject.GetComponentInChildren (System.Type type) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineGameObjectBindings.gen.cs:59)
UnityEngine.GameObject.GetComponentInChildren[GameObject] () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineGameObjectBindings.gen.cs:80)
UnityStandardAssets.Characters.FirstPerson.ActionBarButtonDrag.Update () (at Assets/Scripts/ActionBarButtonDrag.cs:30)

namespace UnityStandardAssets.Characters.FirstPerson{
    public class ActionBarButtonDrag : MonoBehaviour, IDropHandler {

        public DragDrop dragDrop;
        public InventoryV2 inventoryV2;
        public ActionBar actionBar;
        public Image itemIcon;
        public int itemId;
        public GameObject itemIconGO;
        public Transform tempParent;
        public GameObject erasedChild;

        private int tempID;

        // Use this for initialization
        void Start () {

        }
       
        // Update is called once per frame
        void Update () {
            if(transform.childCount == 1){
                erasedChild = gameObject.GetComponentInChildren<GameObject>();
            }
       
        }
}

GameObject is not a component that you can get
if you just want to get the child GameObject of some the GameObject, use transform.GetChild(0).gameObject

Will that let me destroy the child?

Anyone knows how I can get the child of an object and destroy it??

foreach (Transform child in go.transform)
        {
            Destroy(child.gameObject);
        }

That will destroy all children. Sounds bad :slight_smile:

Did you not even try my solution? It will do what you want, and would take 30 seconds to try for yourself

I not only tried your solution. I implemented the basic concept all over my code, for many other things. You help me make it more efficient. Sorry I forgot to thank you :))