Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Sliced sprite for scalable image not working properly?

Discussion in 'UGUI & TextMesh Pro' started by lupidan, Aug 21, 2014.

  1. lupidan

    lupidan

    Joined:
    Jan 14, 2014
    Posts:
    47
    I am struggling a bit trying to get a button with a sliced sprite. My ortographic camera size is 5 and I am creating a menu using a World Space canvas. However, for some reason, the sliced image UI element is not working as I expected. The result is a blurry image, that only starts streching at around 20 units.
    I tried changing the Pixels To Units param for the sprite, yet nothing changes. Am I missing something?

    Captura de pantalla 2014-08-21 a la(s) 14.08.12.png Captura de pantalla 2014-08-21 a la(s) 14.00.03.png Captura de pantalla 2014-08-21 a la(s) 14.01.09.png Captura de pantalla 2014-08-21 a la(s) 14.06.42.png
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,194
    So your sprite is 64x64, but your rect is only 23x26. I would need to investigate what we should do in this situation as we have an assumption that the minimum size is the size of the base image currently. Could you raise a bug?
     
  3. lupidan

    lupidan

    Joined:
    Jan 14, 2014
    Posts:
    47
    Sure.

    Maybe you should consider using the Pixels To Units for measuring and stretching?
     
  4. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    you could fix it by trimming all the duplicate pixels from the source image... just make it 21x21 with slices @ 12x10 and it would work i think

    change your shrink into a stretch
     
  5. lupidan

    lupidan

    Joined:
    Jan 14, 2014
    Posts:
    47
    I tried that, and the result is the same, it only starts stretching at 20 units for some reason. I think my only solution right now would be to transform my game to have a unit-pixel ratio (camera size of 320 instead of 5 for example)

    ???
     
  6. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    I have found that Sliced images will scale p happily but scaling down does not work as well. (not tried mipmapped images yet)
    Not sure if its a bug or not yet.
     
  7. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,879
    No bug necessary. If the size is smaller than the combined borders, we scale the borders down so that you don't get rendering artefacts.

    We do (from beta 20 onwards) but it's in relation with the Canvas.referencePixelsPerUnit property. If you set that to 1 (from scripting) then the pixelsPerUnit property in the sprites will be used as-is. The reason this is not the default is that it's not a workable default for screen space UI.

    Also see: http://docs.unity3d.com/460/Documentation/Manual/HOWTO-UIWorldSpace.html
     
    lupidan likes this.
  8. andsee

    andsee

    Joined:
    Mar 20, 2012
    Posts:
    88
    Can you explain why not please? I'm wondering what could be going wrong due to the fact that I've had all my sprites to have a PixelsToUnits value of 1 and my Canvas Reference Resolution to (2048,1536). All seems fine one unity unit becomes one screen pixel which works really nicely as far as a workflow goes and numbers in inspectors etc.

    I've now written a script to set all canvas referencePixelsPerUnit properties to 1 to get my sliced sprites back to what they used to be and all seems fine again.

    However could we please have referencePixelsPerUnity exposed in the Canvas inspector or even better allow us to define a default pixels per unit for the project. This could then drive the default sprite size (when adding new sprites) and canvas referencePixelsPerUnit.
     
  9. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,879
    Setting up importer default values is out of scope for 4.6. Also, for people using sprites both for the 2D feature and for UI, just setting the pixelsPerUnit value to 1 for all sprites might not be an option, even not on a per-sprite bases if some sprite is used both for 2D and UI.

    One of the coming betas will allow setting a referencePixelsPerUnit value in the Inspector.
     
  10. andsee

    andsee

    Joined:
    Mar 20, 2012
    Posts:
    88
    This brings up a specific point, ideally the image component would allow you to set a scaler of the pixelPerUnit value or override so that in instances where you're using a sprite from an area of the game that uses a different pixelsperunit to the canvas value you can adjust the size of the boarder of the sliced image appropriately.

    I think I understand your original comment now; 1 is not a workable default because it differs from the default of 100 for the sprite importer, rather than 1 is not a workable pixels per unit value. Totally agree that the defaults should be aligned, just a shame that the arbitrary value is not 1 lol ;-). But history takes it course and I guess 100 made sense for in game sprites where you probably want 1 to equal a meter in the game world.
     
  11. BergOnTheJob

    BergOnTheJob

    Joined:
    Oct 9, 2019
    Posts:
    10
    To get the Sliced setting to work on my image, I had to set the Pixels Per Unit to around 120. Less gave me squishing like the image wasn't sliced properly in the Sprite Editor, and More started to create space that wasn't there so my end circles split in half vertically in the Sprite Editor were giving me an extended flat area between the upper and lower rounded corners on the ends.

    I assume these values are particular to my setup and image, but this idea might help others.
     

    Attached Files: