Search Unity

Question UI Image scales differently dragged directly to Canvas

Discussion in 'UGUI & TextMesh Pro' started by Holonet, Dec 6, 2020.

  1. Holonet

    Holonet

    Joined:
    Aug 14, 2017
    Posts:
    84
    I'm just creating a selection cursor using a .PNG that I made so I can create a template selection screen using the new input system.

    So, I created a canvas, and within it, a UI Image. I set the source image to my PNG, added the PlayerInput and my script, etc... and then made it a prefab. When a controller button is pressed, I instantiate it (with the PlayerInput.Instantiate of course, not the vanilla one - but shouldn't matter), and parent it to the canvas.

    This "works," but I get some dumb behavior :p. The cursor becomes enormous (I'm using screen space - camera, BTW). I figured out that if I drag my prefab into the scene, it's huge...but if I drag it directly into the canvas, it appears as I want it. So it's clear that PlayerInput.Instantiate is creating it in the scene, then parenting it, which makes sense.

    To get it to work, I have to edit my prefab so the size is absurdly small, and that gets me what I want, but it's not great for sharing...then if I play with it inside the canvas as done when creating it, it's inviso-small. Also, the prefab editing doesn't make sense. I mess with stuff in the rect transform, etc... just from clicking on it once, and it sticks. But if I actually open the prefab, or drag one in and hit apply overrides, it doesn't stick...bass ackwards... o_O

    Anyone able to shed some light on this?

    EDIT: I "improved" the situation by instantiating, then parenting, then setting the local scale to 1,1,1. Apparently, instantiate skews the scale when the UI image is plopped NOT in the canvas. It seems scrooged, but I don't know if this is a (shock) Unity bug or if I'm just missing something.
     
    Last edited: Dec 7, 2020