How to avoid scaling heritage when parenting.

Hello everyone.
Have you ever tried to parent a gameObject un under a scaled father ?
The scaling in herited, and your GameObject is scaled with weird scaling parameters.
But how setup a child under a scaled parent without impacting the scale ?
Try this context:

	GameObject myCubeAsParent = GameObject.CreatePrimitive(PrimitiveType.Cube);
	myCubeAsParent.transform.Translate(1,2,3);
	myCubeAsParent.transform.Rotate(25,45,65);
	myCubeAsParent.transform.localScale = new Vector3(2,0.5f,5);
	
	GameObject mySphereAsChild = GameObject.CreatePrimitive(PrimitiveType.Sphere);
	mySphereAsChild.transform.position = myCubeAsParent.transform.position;
	
	mySphereAsChild.transform.parent = myCubeAsParent.transform;

As a start, I found that:
Instead of parenting, let’s match the roation of the parent first:

mySphereAsChild.transform.rotation = myCubeAsParent.transform.rotation;
mySphereAsChild.transform.parent = myCubeAsParent.transform;

It works !
Now The scale is preserved, but the gameboject is rotated as the parent, so now I need to reset the rotation to
(By rotating in UI, I found these empiric values : (350,25,300) )
Anyone have some clues to findout how to restore/preset basic transform values while parenting ?

Create an empty GameObject. It has a scale of 1x1x1. Assign the scaled object as the parent. Then assign the empty GameObject as the parent to your desired child object. Now the Hierarchy should look like this:

MyCubeAsParent
    EmptyGameObject
        MySphereAsChild

I tried this, and somehow it worked. Apparently it only scales the object according to the immediate parent’s local scale. The code looked something like this:

var emptyObject = new GameObject();
emptyObject.transform.parent = myCubeAsParent.transform;
mySphereAsChild.transform.parent = emptyObject.transform;

It’s not clear what elements of the parent’s transform you want inherited by the child, and what elements you don’t, so I can’t give you a very exact answer. I will tell you, though, that parenting an object to a parent with a non-uniform scale will generally give you results that you weren’t expecting. If you want to scale the parent mesh, it’s a better idea to make the two meshes siblings, and put the scale in the mesh node instead of the (new) parent node.

You can store the scale before before parenting then reapply it, did the trick for me

Vector3 scale = mySphereAsChild.transform.localScale;
mySphereAsChild.transform.parent = myCubeAsParent.transform;
mySphereAsChild.transform.localScale = scale;