How can i check if my gameobject has a parent?

So i am grabbing my objects in vr by making them child objects of my controller and i want to check on the object if it is being held like this:

void Update ()

{
    if (transform.parent.gameObject.CompareTag("Controller"))
    {
        print("true");
        isBeingHeld = true;
    }
    else if(!transform.parent.gameObject.CompareTag("Controller"))
    {
        isBeingHeld = false;
        print("false");
    }

}

but this only returns true and never gets to false :frowning:

Apart from the redundant else if statements (you don’t need the second check), you can just do else.
I don’t see anything wrong with the code.

What you should check is if this Update is running on the child object, and you are actually making it not a child of the controller when you don’t want it to print true.
And if you have this tag elsewhere other than the controller.

if(transform.parent == null)
//Your gameObject has no parent
else
//Your gameObject has a parent