Question by
Irregular · Mar 04, 2018 at 02:30 PM ·
spriteunityeditoronpostprocesstexture
Updating alpha with setpixel on texture only works on the edges of a sprite
I'm trying to import an RGB sprite with a pink transparent color.
I've added this code:
private void OnPostprocessTexture(Texture2D import)
{
import.filterMode = FilterMode.Point;
for( int x = 0; x < import.width; x++ )
{
for( int y = 0; y < import.height; y++ )
{
Color color = import.GetPixel(x, y);
if ( Math.Round(color.r, 1) > 0.9f
&& ( Math.Round(color.g, 1) > 0.4f && Math.Round(color.g, 1) < 0.6f)
&& Math.Round(color.b, 1) > 0.9f)
{
import.SetPixel(x, y, Color.clear);
}
}
}
import.Apply();
}
And it does work, however the end result is that Unity ignores the alpha at the edges of the sprite and I have no idea why. This code sets the color on all the pixels that I want to set but unity just doesn't honour the alpha on some of them and just ignores the alpha instead.
The result looks like this:
Could anyone help me?
BTW if anyone knows of a better way to make unity import a color as transperancy I would love to hear it, I can't believe this isn't a simple flag some where.
example.png
(5.8 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612153924im_/https://answers.unity.com/themes/thub/images/avi.jpg)