How to keep the same position and rotation

Hi, I have a child gameobject that follows the parent, until I call an Animation Event function to leave the parent -

void LeaveParent()

{

transform.parent = null;

}

It works, but the transform changes from the last animation frame positions, to a new position. So, how can I keep the position/rotation of the last animation frame when I call the the LeaveParent() method?

see what the X,Y,Z of the position and rotation is on the last frame and add these lines:

transform.position = Vector3(x, y, z);
transform.rotation = Quaternion.Euler(x, y, z);

(Of course you replace x,y,z with the values you found on the last frame)