- Home /
changing sprite color makes sprite disappear
i changed the sprite color in my script like this myRenderer.color = new Color32(255, 255, 255, 0); and now my sprite has disappeared ive looked further into this and found that the way i did it is probably not the besst route to take for what im trying to achieve but now my sprite has vanished, hes still there but you cant see him, can anybody help me get him back please? ive attached a photo
Answer by Peecha · Feb 19, 2016 at 04:45 PM
Color32(255, 255, 255, 0) fourth parameter is alpha... you set it to zero so its invisible. Change it to 255.
Thank you! I was using Color and not Color32 and was setting it in the Inspector instead of through code, but for some reason Alpha was 0 for me too.
Answer by martipello · Feb 19, 2016 at 03:13 PM
okay it seems id fixed it but had to restart unity to get it to stick sorry to ask prematurely
Answer by IsaiahKelly · Feb 19, 2016 at 03:59 PM
You've set the new color's alpha (transparency) value to zero. Making the sprite completely invisible.
Color32 has four color values: Red, Green, Blue, and Alpha. You need to set the last value to something above 0 to make it visible. 255 = completely solid. e.g. myRenderer.color = new Color32(255, 255, 255, 255);
However, the example image above looks to have an invisible sprite with only 50% alpha value. In this case I would suspect a sorting layer issue is hiding the sprite behind another one. $$anonymous$$aking it appear invisible.