Looks like if a parent has a scale that is not 1,1,1 and you set that as a parent to an object, programmatically, that object gets auto-scaled to something weird because of the scale on the parent.
Is there a way to set a parent while ignoring the scale?
For anyone landing on this thread in 2020, Transform.SetParent takes an optional boolean parameter to support this: Unity - Scripting API: Transform.SetParent
WorldPositionStays - If true, the parent-relative position, scale and rotation are modified such that the object keeps the same world space position, rotation and scale as before.
So, the code you want is:
If you want to set the parent while only keeping its original scale - that is, not it’s rotation and position, you’ll have to temporarily store those before setting the parent, and set them back after.
It is because once you are linking gameobject in the hierarchy the child get its local transform in function of the parent. Normaly if you change the scale you will see only transform.localScale so if the gobj is not a child so its scale is in function of world space and if it is a child so its local properties are then changed to local space . It makes sense after a certain amount of time…hope you understand. Good luck
If you want to set the position and/or rotation only, you can add a Parent Constraint: Unity - Manual: Parent Constraints