#SetParent() and global position problems

1 messages · Page 1 of 1 (latest)

wet flower
#

I am trying to create an object and then create multiple smaller objects inside it.
The parent object has the global coordinates of 0,0,0. The first child also has the coordinates 0,0,0 and the other children are offset from those. The problem arises after I use the SetParent() method WITH worldPositionStays "true".

Here is the console output:
Global position before parent: x:0, y:0, z:0
Local position before parent: x:0, y:0, z:0
Global position after parent: x:4,470348E-08, y:0, z:1,192093E-07
Local position after parent: x:-6,34092E-09, y:0, z:1,5

Why is this happening? Shouldn't the global position be the same regardless? How can I fix this as it happens with all children of that object? Thanks in advance.

Quick edit: All children appear where they should within the parent object. I just need the coordinates to match up with the ones I set them to be before assigning them to the parent.

little lodge
#

Keep in mind, that xE-y means x time 10 to a power of -y.
So 4.470348E-08 would be 0.00000004470348. That's why it doesn't appear elsewhere as well, because it's pretty much in the same location.

Unity's coordinates are float-based and as such will always be subject to small imprecisions.
So though it may look weird in the editor, the position "changing" should not be an issue.

wet flower
#

Thank for responding. Any way to "fix" this? The coordinates and their offsets are precalculated and I need them to stay the same without any discrepancy.

little lodge
#

You'd probably be able to store the world position before parenting and then re-assign it afterwards.
But frankly if something relies on an object's exact position (or another exact floating-point value), there's something wrong with your code.