Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unity UI Suggestion : add a pixelsperunit factor to UI.image / allow multiple pixels per unit per texture

Discussion in 'Unity UI & TextMesh Pro' started by Setsuki, Oct 3, 2018.

  1. Setsuki

    Setsuki

    Joined:
    Aug 21, 2012
    Posts:
    19
    Currently, the Image component uses the sprite's pixels per unit variable in order to determine the sizes when slicing and tiling an image.
    It is currently impossible for a user to have different slicing using only one texture. The only solution I have found was to duplicate the texture file and reimport it, which quickly bloats the texture atlas.

    By copying the Image script, and simply applying a factor to the pixelsPerUnits variable, I have been able to make the slicing manually editable :


    It would be handy to either make the pixelPerUnit variable virtual in order to be overriden, or adding a factor variable.

    You can find the linked feedback ticket here :
    https://feedback.unity3d.com/sugges...sh-allow-multiple-pixels-per-unit-per-texture
     
    aurelien-morel-ubiant likes this.
  2. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    60
    Hello @phil-Unity
    do you think this feature could be useful (cause for us it seems to be a good one) and not too touchy to be accessible by script without create a custom Image component ?
     
  3. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,094
    Hasn't seen this thread but i honestly stared at the gif for minutes just mesmerized by the fact we didn't think of this. Personally i think its simple and handy. I will pass it on to get it done (soon (tm)).
     
    Ferazel likes this.
  4. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    60
    @phil-Unity thanks for the answer ! It's really great to hear that !!
    We will abuse of your kindness by linking you this associated problem in the 2D part (which is maybe a UI trouble we didn't know where to post those 2 topics )

    By soon, do you think it could land into 2018.3 ? (I don't think so but we try)

    The issue/question is in this forum topic : https://forum.unity.com/threads/help-getting-a-sprites-atlas-during-build.576781/

    If you have any hint for this more or less related issue/question ?
     
    Last edited: Nov 7, 2018
    Setsuki likes this.
  5. Setsuki

    Setsuki

    Joined:
    Aug 21, 2012
    Posts:
    19
    Glad this is getting noticed ! The link @aurelien-morel-ubiant is accurate as having multiple ppu for one texture would make the gif above available not only for the Image class, but for every classes using Sprite, which sounds like a more generic solution.
     
  6. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    450
    Sorry for the ad, but if you cannot wait for it, you can use Better UI which allows you to do something very similar (and is even a bit more powerful).
     
    Setsuki likes this.
  7. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,094
    So not for 2018.3 for sure as its already in beta and its a "maybe" for 2019.1, depends how fast we could get to it.

    As for the second part i'm not sure off hand, and i think 2D is the better team to answer as technically they own the sprite system.
     
  8. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    726
    it's not the most elegant solution in the world, but you can actually accomplish this by inheriting from the Image class rather than fulling copying it into your own duplicate class.

    first create a public new float pixelsPerUnit to hide the variable from the base class. It so happens that even though this property is not virtual, all of the functions that access it are, so just override all of those functions, and copy paste there contents into your custom Image class so that they use your new pixelsPerUnit variable. There is quite a lot of copy pasting still and it's obviously not ideal, but at least you will still be able to use your custom image class with other UI classes that require Images
     
  9. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    306
    I also would very much like to see this feature. This could save us so many duplicated sprites because the artists want different corner radius on various buttons/backgrounds/etc.