I’m currently trying to implement a method, that returns true or false based on if it is NPOT (non-power of two) or it is POT. In the “Advanced” settings in the Unity editor there’s a enum-value called Non-Power of 2 which I want to read from a script, but I can’t seem to find a method similar to isReadeable to see what is selected. What should be the proper way to solve this problem?
This is a common way to test if an integer is POT or not, which (was originally) the only question in the title and the first sentence of the body of the question.
public static class NPOTExtensions
public static bool IsPowerOfTwo(this int i)
return ((i & (i - 1)) == 0);
public static bool IsPowerOfTwo(this Texture t)
return t.width.IsPowerOfTwo() && t.height.IsPowerOfTwo();
In the body of the question you go on to talk about wanting to read the value of the Non-Power of Two import setting, which is a different thing.
That field only even appears if the raw data is non-power-of-two (which I would imagine the editor works out using a function like I’ve shown), and tells Unity how to handle the fact on import. It’s not a property of the imported texture.
If you actually need to access the NPOT setting for a NPOT texture, you’re probably best off explaining why, because that’s a whole other ball game. I believe you could do something using an asset preprocessor and the UnityEditor.TextureImporter class (which defines the behaviour) but I’ve already gone further than necessary if all you actually need to do is handled by the code above