Straight forward code, straight forward problem:
itemGraphics[itemSlot.IndexInList] = (GameObject)Instantiate(itemSlot.Item.ModelAsset);
itemGraphics[itemSlot.IndexInList].transform.parent = itemSlot.transform;
itemGraphics[itemSlot.IndexInList].transform.lossyScale.Set(1, 1, 1);
itemGraphics[itemSlot.IndexInList].transform.rotation = Quaternion.identity;
It’s giving unexpected values in the inspector for scale and rotation. The parent (itemSlot) of the child (itemGraphic) is a worldspace ui element, so it has a RectTransform, where as the child itemGraphic is a regular gameobject with a regular Transform.
I tried editing local scale and local rotation instead; same issue. I tried parenting after setting scale and rotation (tried both local and world) and still same issue.
All I want to do is child a 3D graphic to a 2D UI element.
EDIT: Sceenshots of the output:
After changing scale to 1 and rotation to 0 through inspector at runtime:
EDIT: I just figured something out. It seems to be scaling down the child’s x and y by the parent rectTransform’s width and height. The rectTransforms width and height is 50, so if I scale the child’s x and y to 50, it returns to normal.
I guess if there’s no better way, I can just code it to scale up the child by the parents width and height…
EDIT: ^Actually that still doesn’t work. For some reason the final scale is some crazy high numbers in the thousands. Something’s retransforming it after I do.
Also if I change the values at runtime in the inspector, if the rotation isn’t 0,0,0, the model skews even though the scale doesn’t change.
This is all very strange behaviour, I wish I could fine documentation on how rectTransforms and transforms are supposed to work together.