Keep transforms after parenting object

I am setting my object to a transform values and after that I am making it a child of a parent object. Unfortunately it loses its transforms. So how do I keep the transforms as they are even after parenting?

obj1 = new BABYLON.Vector3(20,30,20);
obj1 .parent = obj2;
obj1 = new BABYLON.Vector3(20,30,20);

It does not lose it per se. It is simply from a global mode (no parent) to a relative mode (where transforms are relative to parent)

good way to get what (I think) you want:

obj1.position = new BABYLON.Vector3(20,30,20);
obj1.setParent(obj2);

Doc: Parents and Children | Babylon.js Documentation (babylonjs.com)

1 Like

Hey thanks I actually found out the issue, it was setting incorrect transforms even though I was parenting it right. Problem was that, it was already set as child to another parent so I had to first unlink that in order to parent it again.

obj1.node.setParent(null);
obj1.position = new BABYLON.Vector3(20,30,20);
obj1.setParent(obj2);