Hiya
I am doing something that requires reading texture data via GetPixels32. I’m working on a moderately sized team, so occassionally people submit assets without the read/write flag set. Is there a way to see if a texture is readable at runtime so I can avoid the game crashing and throw an error instead?
I’m not 100% sure but with the Texture Importer you change the Teture Type to Advanced and there should be an option Read/Write Enabled, and check it, try that out.
I know how to set it as read/write enabled, what I mean is at runtime I want to know if a texture I am grabbing is readable to prevent the game crashing. If there’s an exception I can catch that would probably work too. As it is anytime I run into a texture that’s not readable the game crashes rather than failing gracefully.
Use try/catch.
–Eric
I don’t know the C# equivalent - I was taught by JS to be lazy and not learn what type an exception is - but here’s the JS version:
try {
// something which can throw an exception
} catch ( youMakeUpAVariableNameHere ) {
Debug.Log("An exception was thrown: " + yMUAVNH.message );
}
–Eric
The specific case I was looking for was throwing a UnityException after checking again. Thanks much people!
@Louis’ reply: I’m using C#, so it’s like this for anyone who wants it in C#:
try
{
someTexture2DThatMightNotBeReadable.GetPixels32();
//StuffWithTexture2D
}
catch (UnityException e)
{
Dbg.LogError("The world is ending");
}