Weird bug with setting localPosition

I’m creating a system meant to Instantiate() an image parented another image, giving it a background as a frame. I use backgrnd.sizeDelta to resize the background. Then image.sizeDelta for the image. This works correctly. And so does offsetting the X axis of the image with .localPosition.

However, something is multiplying the Y axis by 13. This drops the image down by the entire height of the image - putting it outside the frame. It’s very consistent, and only happens when I try to set .localPosition. and it doesn’t affect anything else. I’m completely baffled. This is a newly created object and it’s only referenced inside this one tiny method. The offsets both come back correctly as 32 and -32 in Debug.Log and the image is correctly anchored to the top left corner. Weirder still, when I divide the y offset by 13, it doesn’t change anything.

Any ideas what would do this? I would just set the image to the centre and skip offset, but I need it aligned top right.

Are you doing Instantiate(prefab, parent)?

If so then the 13 is probably the prefabs stored Y position. Select the prefab in the inspector and set its position to zero.

I am, actually. Would setting it in code work?

yes

1 Like