Texture2D.GetPixel(int x,int y) Error Message: "x == 0 && y == 0 && blockWidth == dataWidth && blockHeight == dataHeight "

Hello, My name is Jade,

I’m trying to get the Color of a pixel from a texture called “scoreMap”.

The code I have is

public int getScoreValue(Vector2 uvCoord)
{
		//First, get the pixel color of that uvCoord
		int pixelX = (int)(uvCoord.x * scoreMap.width);
		int pixelY = (int)(uvCoord.y * scoreMap.height);

		Debug.Log("X: " + pixelX + " Y: " + pixelY);

		Color pixelColor = scoreMap.GetPixel(pixelX,pixelY);

		Debug.Log("Color: " + pixelColor);

		...
}

However, I get the log error:

x == 0 && y == 0 && blockWidth == dataWidth && blockHeight == dataHeight UnityEngine.Texture2D:GetPixel(Int32, Int32) ScoreMap:getScoreValue(Vector2) (at Assets/ScoreMap.cs:33)'

Which comes from line 9 : “Color pixelColor = scoreMap.GetPixel(pixelX,pixelY);”

scoreMap is a 512x512 texture, and the pixels I’m feeding the method are valid.
Here’s a picture of the output:

48213-screen-shot-2015-06-14-at-112117-am.png

Interestingly enough, it does return the correct color for that pixel on my texture, but it fills my log with error messages and butchers my FPS. Does anyone here know what could be causing this?

Also, my texture settings for scoreMap:

Thanks,

The texture has to be in the ARGB32, RGB24 or Alpha8 texture format.

So I changed Format from “Automatic Compressed” to ARGB32.

This information wasn’t on the GetPixel documentation page, but on the SetPixel page Unity - Scripting API: Texture2D.SetPixels .

May be useful in the future to have Unity print out a more helpful error message.