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?
using UnityEngine;
using System;
using System.Collections;
public class ColorPicker : MonoBehaviour {
public Texture2D Skin;
public Texture2D colorPicker;
public int ImageWidth = 100;
public int ImageHeight = 100;
private Color[] SkinColors;
void OnGUI(){
if (GUI.Button(new Rect(10, 10, ImageWidth, ImageHeight), colorPicker)) {
Vector2 pickcol = Event.current.mousePosition;
int xpos = Convert.ToInt32(pickcol.x);
int ypos = Convert.ToInt32(pickcol.y);
Color col = colorPicker.GetPixel(xpos,41-ypos);
SkinColors = Skin.GetPixels();
for(int x = 0; x < SkinColors.Length; x++)
{
SkinColors[x] = col;
}
Skin.SetPixels(SkinColors);
Skin.Apply();
}
}
}
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:
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 the way, if you generate a texture with code, then use GraphicsFormat.R32G32B32A32_SFloat to be able SetPixels(…) method on it later. For example:
Texture2D myTex= new Texture2D(sizeX, sizeY, GraphicsFormat.R32G32B32A32_SFloat, TextureCreationFlags.None);
myTex.SetPixels(...); // Will be performed successfully.