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.
  2. Dismiss Notice

SetPixels - Unsupported Texture Format

Discussion in 'Scripting' started by reset, Sep 5, 2012.

  1. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Hi

    I am using a colour picker to change the colour of a texture - part of a larger plan I have in mind - but I am getting
    "Unsupported texture format - needs to be ARGB32, RGBA32, RGB24 or Alpha8" on Skin.SetPixels(SkinColors);

    Skin is an imported texture that has been converted to ARGB32 in Unity and the var Col is ARGB so I am
    not sure why I am getting this error.

    Please help?

    Code (csharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections;
    4.  
    5. public class ColorPicker : MonoBehaviour {
    6.    
    7.     public Texture2D Skin;
    8.     public Texture2D colorPicker;
    9.     public int ImageWidth = 100;
    10.     public int ImageHeight = 100;
    11.     private Color[] SkinColors;
    12.  
    13.  
    14.     void OnGUI(){
    15.  
    16.         if (GUI.Button(new Rect(10, 10, ImageWidth, ImageHeight), colorPicker)) {
    17.  
    18.                 Vector2 pickcol = Event.current.mousePosition;
    19.                 int xpos = Convert.ToInt32(pickcol.x);
    20.                 int ypos = Convert.ToInt32(pickcol.y);
    21.                 Color col = colorPicker.GetPixel(xpos,41-ypos);
    22.                 SkinColors = Skin.GetPixels();
    23.            
    24.                 for(int x = 0; x < SkinColors.Length; x++)
    25.                 {
    26.                     SkinColors[x] = col;
    27.                 }
    28.                 Skin.SetPixels(SkinColors);
    29.                 Skin.Apply();
    30.            
    31.         }
    32.  
    33.     }
    34.  
    35. }
     
    Last edited: Sep 5, 2012
    Necronomicron likes this.
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Have you got the Read Write Enabled option switched on the the texture import settings? (Set the texture type to Advanced to see this option.)
     
    OneSketchyGuy likes this.
  3. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    I'm kind of late, but I might be able to prevent people from asking the same question again,
    As the error says, you need to change the format of the texture to one of the given formats:

    By default "Automatic Compression" is selected.
     
  4. GQPHD

    GQPHD

    Joined:
    Nov 15, 2012
    Posts:
    8
    I love this post. Magiichan saved me.

     
    twobob and Magiichan like this.
  5. Nasir41

    Nasir41

    Joined:
    Nov 11, 2015
    Posts:
    3
    But what about the image size when we don't compress it......
     
  6. husnain_ijaz3

    husnain_ijaz3

    Joined:
    Apr 27, 2017
    Posts:
    3
    Are these options available in Unity 2017.3.0f3 ? I want to use ARGB 32 Bit but can't seem to find it anywhere. Any help would be really appreciated
     
    Fenikkel likes this.
  7. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Maybe? upload_2018-9-10_14-42-37.png
     
    Ali-Nagori and burtonposey like this.
  8. OlliIllustrator

    OlliIllustrator

    Joined:
    Nov 1, 2013
    Posts:
    71
    Thank you, Magiichan, that saved me a lot of headache!
     
    Magiichan likes this.
  9. deenasty

    deenasty

    Joined:
    Nov 17, 2017
    Posts:
    3
    Thank you for saving me time. It works
     
    Magiichan likes this.
  10. sickb0y247

    sickb0y247

    Joined:
    May 29, 2014
    Posts:
    51
    Still relevant 2020. Thank you!
     
    Magiichan likes this.
  11. nikhilpatel3012

    nikhilpatel3012

    Joined:
    Oct 16, 2019
    Posts:
    1
    I love this post.
     
    Magiichan likes this.
  12. threethree33

    threethree33

    Joined:
    Feb 10, 2020
    Posts:
    1
    worked for me
     
  13. rodneya63

    rodneya63

    Joined:
    Oct 5, 2017
    Posts:
    4
    I have spent 3 days trying to get this to work and nowhere until now did anyone mention that the format is not set the same as what is loaded. Being new I didn't appreciate the bottom part of the window (once again not mentioned anywhere by anyone else).

    Thank you so much.



    QUOTE="Magiichan, post: 1667095, member: 519638"]I'm kind of late, but I might be able to prevent people from asking the same question again,
    As the error says, you need to change the format of the texture to one of the given formats:

    By default "Automatic Compression" is selected.[/QUOTE]
     
  14. ycanatilgan

    ycanatilgan

    Joined:
    Aug 23, 2017
    Posts:
    30
    Perfect solution, thanks!
     
    Magiichan likes this.
  15. TheBlatantOne

    TheBlatantOne

    Joined:
    Feb 2, 2014
    Posts:
    4
    Was struggling with this too, thanks!
     
    Magiichan likes this.
  16. umarhyatt

    umarhyatt

    Joined:
    Nov 20, 2020
    Posts:
    3
    thanks
     
    Magiichan likes this.
  17. oOPHINOo

    oOPHINOo

    Joined:
    Jun 20, 2017
    Posts:
    1
    Absolute legend. Thank you
     
    Magiichan likes this.