Hi there,
I have trouble understanding how `Transform.SetParent()`'s `worldPositionStays` parameter works, specifically when parent is set to `null`.
The scripting reference says:
> 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. Naturally, I usually set it to `true`, because I don't want parenting to change position, rotation, or scale. So I was surprised when trying to "unparent" with `transform.SetParent(null, true);` the inverse of the parents' scale was applied! Even though if I carefully think about it, `localScale` relative to `null` parent (assuming the scale of `null` is (1, 1, 1)) would mean just `localScale`, I still expected that it will automatically compensate for the relative differences between the original and new parents' scales. Note that if I "unparent" with `worldPositionStays = false` it works as I originally expected.
**EDIT:** Interestingly, [this answer][1] says the *opposite* about how `worldPositionStays` works...
**So, basically, my questions are:**
- why does `transform.SetParent()`'s `worldPositionStays` work this way when the parent is set to `null`?
- is the above observed the intended behaviour, or is it a bug? (I was expecting it to compensate for scale differences)
- in general, what is the recommended way of using `worldPositionStays`?
Also, I *seem* to remember `transform.parent` being deprecated in Unity 5 and `worldPositionStays` defaulting to `false`... does my memory play tricks on me, or was this changed recently? [1]: https://gamedev.stackexchange.com/questions/102518/unity-c-object-scaling-when-parenting-by-script
I have trouble understanding how `Transform.SetParent()`'s `worldPositionStays` parameter works, specifically when parent is set to `null`.
The scripting reference says:
> 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. Naturally, I usually set it to `true`, because I don't want parenting to change position, rotation, or scale. So I was surprised when trying to "unparent" with `transform.SetParent(null, true);` the inverse of the parents' scale was applied! Even though if I carefully think about it, `localScale` relative to `null` parent (assuming the scale of `null` is (1, 1, 1)) would mean just `localScale`, I still expected that it will automatically compensate for the relative differences between the original and new parents' scales. Note that if I "unparent" with `worldPositionStays = false` it works as I originally expected.
**EDIT:** Interestingly, [this answer][1] says the *opposite* about how `worldPositionStays` works...
**So, basically, my questions are:**
- why does `transform.SetParent()`'s `worldPositionStays` work this way when the parent is set to `null`?
- is the above observed the intended behaviour, or is it a bug? (I was expecting it to compensate for scale differences)
- in general, what is the recommended way of using `worldPositionStays`?
Also, I *seem* to remember `transform.parent` being deprecated in Unity 5 and `worldPositionStays` defaulting to `false`... does my memory play tricks on me, or was this changed recently? [1]: https://gamedev.stackexchange.com/questions/102518/unity-c-object-scaling-when-parenting-by-script