How do I unparent an object without changing it's position?

Fix: The reason I wanted to unparent the bat was to stop it from moving with the player, but for some reason that I still don’t understand the bats position got locked when I unparented it so I couldn’t move it, so I settled and made it so the player can’t move when I don’t want the bat to move. Yeah, it’s lazy but hey, it works.

Not much to say here, the title pretty much sums up the whole question.
Here’s what I’ve tried

Vector3 originalBatPos = bat.transform.position + transform.position;

bat.transform.parent = null;

bat.transform.position = originalBatPos;

It depends. Are you trying to preserve the object’s position in the world? Or are you trying to preserve the object’s position relative to its parent?
```csharp
*// This will preserve the bat’s local position
bat.transform.SetParent(null, false):

// This will preserve the bat’s world position
bat.transform.SetParent(null, true);
// which is also equivalent to
bat.transform.parent = null;*
```

I’m trying to preserve the bats world position, but the solution you gave me didn’t work. I’m gonna run some debug statements to see what’s going on