Parenting and Unparenting Objects?

The basic idea of what I’m trying to do is this.

I have a player model and a crate. Each parented to their own game objects. What I want to have happen is when the player collides with the crate, the crate becomes parented to the player parent so that they move together when the player is moved.

I also need to have it so that under a certain condition the crate becomes parented to its original parent object without screwing up the position or anything.

I know parenting to an object is pretty simple. But with the un-parenting is it possible to store the name or tag of the original parent in a variable and use that to reparent an object to the original parent?

private Transform originalParent;

void Awake()
{
 originalParent = transform.parent;
}

void AssignNewParent( Transform newParent )
{
  transform.parent = newParent;
}

void AssignOriginalParent()
{
  transform.parent = originalParent;
}

Through your script, you can remember what your original parent was, and revert back to it any time. You could also assign a new parent at any time as well, by calling AssignNewParent() and passing the new transform to attach on to.

Awesome. Thank you much.