- Home /
Why is new UICanvas so big ?
Hello everyone, i'm struggling a little with the new UI
I got a sprite that is 80x120 px i got a canvas which render mode is set to world space (because i want to write texte onto the specific sprite) the canvas Rect is 50x50 px,
So why its size in the editor is WAY bigger that my sprite?? Note that on the picture below my game zone is 900x600px, and as you see the 50x50px rect seems oversized. I cannot make text matches the sprite (and the text is way too big too)
Thanks
[FIX]
To force your Hierarchy Canvas UI to the same resolution as the Camera View in your Unity Editor Scene window resolution (i.e. not ridiculously massive), or in other words get the Canvas to fit into the Camera size in the Scene, do the following:
Set the Canvas component's Render $$anonymous$$ode to Screen Space - Camera.
$$anonymous$$ake sure you select or drag the relevant Camera from the Hierarchy to the Render Camera field in the Inspector.
Answer by DiegoSLTS · Feb 24, 2015 at 01:58 PM
Canvas are big because their size in pixels is represented as unity "units" in the scene. A 800x600 canvas will match the size of a 800x600 quad. Your 50x50 canvas is 50 times as wide as the default unity cube. This also happens for the rest of UI elements.
Something I don't understand is if you want the sprite to be part of the canvas too, or if it's an object in the world a you want a canvas to follow it.
If you want to display a sprite inside a Canvas do not drag the sprite directly, add a UI Image game object and set it's "sprite" property to the sprite you want. Then you can clic "set native size" to display the sprite in it's real resolution.
If you want a text to be displayed over the sprite (with the sprite inside the canvas), make the text a child of the image, so the positioning will always be relative.
A simplified hierarchy could look something like this:
Main camera
Canvas
... Image <- With the sprite setup in the image component
...... Text <- With anchor in the center
If the sprite is a world object and you want the canvas to follow it you should't be using a canvas so big, change the size to the size you want, then change the "Dynamic pixel per unit" in the Canvas Scaler component. For example, if you set it to 100, and set a text's font size to 50, it's height (visually) will be half a Unity unit. Tweak those values and you should be able to place the text over the sprite.
Thanks for your answer, $$anonymous$$y main goal was to get a text displayed into a sprite game object, So I tried your hierarchy Canvas (sized to 9x3) ..UI Image with sprite wanted (changed to 0.75x1.19 to get the correct size) ..UI Text anchor at center
But still got the size problem, even with a font size set to 1 the text is way too big, and i cannot lower it even playing with dinamyc pixel unit
There's really something that I don't get in the use of the unity scales
I've tested what you said and it does some weird things, yes. $$anonymous$$aybe I don't understand how those pixel per unit values work. I managed to change the rendered text size by using a really high "dymanic pixel per value" (like 2900), but that's hardly ideal, it would be a pain to maintain something like that, it looks so random...
yes, I agree. But I'm open to suggestions ;) Do you see a simpliest way to add text on sprites ?
I guess you can add a big canvas (like a 800x600 canvas) and then scale it down a lot. When the canvas width and height are close to common screen resolutions the text's size seems to work O$$anonymous$$.
Answer by Eidern · Feb 25, 2015 at 10:39 AM
Oh WAIT ! For some reason (that we need to understand),in your hierarchy Canvas ..Image ...Text if you click on the Image UI "Set Native Size", then the Text component finally shrinks itself to the sprite resolution (after you play a bit with the dynamic pixel value)
So okay your answer was a good one, with one addition : "Set Native Size" of the image. Thanks again