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.

Question Get the width and height displayed in the texture preview window

Discussion in 'Editor & General Support' started by kloot, Nov 1, 2022.

  1. kloot

    kloot

    Joined:
    Mar 14, 2018
    Posts:
    43
    I'm trying to figure out how to (programmatically, in editor mode) get hold of the same with and height as is displayed in bottom of the preview window of a Texture inspector.

    TextrurePreview.png

    It seems to take the compression into account and is not necessarily the same as the width and height of the file on disk.

    Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    31,294
    Those values look more like the NPOT settings... have you fiddled with those appropriately?
     
  3. kloot

    kloot

    Joined:
    Mar 14, 2018
    Posts:
    43
    I'm not sure how those values are calculated, but I'm looking for a way to get to them programmatically. They don't seem to be accessible either through the Texture2D or the TextureImporter.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    31,294
    I think they actually are... if you have an NPOT texture and set it to round up to nearest POT, then use the in-Unity reference to that Texture2D, it will return POT dimensions, not the original image dimensions, so that's how you would get it.

    If you're talking about a Sprite on the other hand, that's completely different and dependent on a huge cascade of other situations, like atlassing, multi or single, etc.