Canvas - Sprite small...

I have a canvas, inside the canvas is a Rect Transform acting as a Container for HudDisplay which is a panel. I instantiate a gameobject that contains a sprite and set it’s parent as HudDisplay.transform. When this happens, the sprite is very smalll… it’s local scale is 1,1,1 I’m not sure I understand why when I drag the same gameobject directly into the Canvas hierarchy it appears the correct size but when I set it’s parent as the HudDisplay panel it’s tiny…

Canvas is confusing!!!

indeed it is

When moving an item in the hierarchy unity will try to preserve the original size and thus alter the scale of the dragged object.

You can either determine the proper scale by transforming the lossy scale into a local scale so that the lossyscale (world scale) is 1, or you can calculate the proper scale for the item based on your specific situation, perhaps the scale is a knowable value you can simply store and assign from the script that instantiates?

You can also public void SetParent(Transform parent, bool worldPositionStays);
with true, so that the scale remains, then change the position manually or have a layout group do that for you.

Next up canvas:
canvas has a size (think of this as pixels in an image), 1 pixel is 1m (i think) with scale 1
for world UI, I usually scale the canvas down to 0.01

http://docs.unity3d.com/Manual/script-CanvasScaler.html
you can alter the amount of pixels within the size with the scale factor and the reference pixels per unit

scale is the size of each element, it inherits scale from the parent and then this factor is applied
Reference Pixels Per Unit will scale the sprites accordingly

step 1 make a standard canvas
step 2 add any element to serve as a scale reference
step 3 alter the canvas to suit your needs (like setting the scale to 0.01)
step 4 tweak the scale factor and ref PPU of the canvas scaler

1 Like

Thanks for the guidance, this will be very useful for me.

Solved my problem. I was using a sprite, not an image… Canvas only renders UI elements. The scale comes in correctly now, thanks for kick starting the process Freeze.