Can you compare a Gameobject to a Variable?

I’m working on an inventory system, and I am very close to being able to click an active slot, destroy the object already there, and then place the new object. The thing is, I am using scriptable objects to make the inventory system because I want a system that I can just make a scriptable object and then it works without any other input needed. I can’t seem to get the active GameObject to link up with the variable on the scriptable object so then I can get the GameObject on the scriptable object that the image is sitting on. I’m sorry if you don’t understand, but its hard to explain. I have the code to look at though on the bottom. I basically go through a loop looking for if the image is the same as the S.O. with the variable of i for the duration of the amount of items(scriptable objects) I have. The main part I need help with is the if statement in the for loop. If you could help that would be great. Thanks!

public void EquipItem(Button clicked)
    {
        if (clicked.gameObject.transform.childCount == 1)
        {
            Destroy(currentOBJ);

            for (int i = 0; i < items.Length; i++)
            {
                if (GameObject.ReferenceEquals(items*.itemSprite, clicked.transform.GetChild(0)))*

{
currentOBJ = Instantiate(items*.itemObj, hand.transform.position, hand.transform.rotation);*
currentOBJ.transform.parent = hand.transform;

break;
}
}
}
else
{
Debug.LogError(“No child”);
}
}

It appears that you’re trying to compare a GameObject to a sprite? Is that correct?

A GameObject on its own doesn’t have any real properties to compare to. You want to use GetComponent to find the component that has the property you actually want to compare to. For example:

SpriteRenderer sr = myGameObject.GetComponent<SpriteRenderer>();
if(sr.sprite == mySprite) 
{
    Debug.Log("They match!");
}

@ahstein , thanks so much. I don’t know why i didn’t realize, but again thank you. All I changed was instead look for the same sprite that the two share. Thanks again!!!