Can not compute type of conditional expression as `UnityEngine.Color32' and `UnityEngine.Color' convert implicitly to each other

From the docs:

Color32 can be implicitly converted to and from Color.

Reality:

error CS0172: Can not compute type of conditional expression as UnityEngine.Color32' and UnityEngine.Color’ convert implicitly to each other

???

My code:

		private static Color32 ray_color = new Color32( 140, 190, 214, 0 );
		[...]
		Color d_ray_color = do_fire ? Character.ray_color : Color.white;
		Debug.DrawRay( gameObject.transform.position, gameObject.transform.forward*range, d_ray_color );

That’s weird, for sure: if both types are interchangeable, the compiler should return any of them instead of stopping with such stupid error message! But the solution is simple: declare ray_color as Color instead of Color32 (actually, Color is the “official” type: almost all code and shaders expect the color defined by 3 or 4 floats).

   private static Color ray_color = new Color32( 140, 190, 214, 0 );

The problem is that a mutual conversion exists. To quote the MSDN page on your error.

In a conditional statement, you must be able to convert the types on either side of the : operator. Also, there cannot be mutual conversion routines; you only need one conversion.

There cannot be mutual conversions. Since each one can be implicitly cast into the other, the compiler doesn’t know which one to choose. In your case, you’d think that the compiler could infer the correct conversion based on the type that you are assigning the value to, but you can’t assume that will work every time because this is also valid (using type inference I mean. You’ll still get the error) :

var d_ray_color = do_fire ? Character.ray_color : Color.white;

Now does the compiler convert the Character.ray_color to a Color or does it convert Color.white to a Color32? That’s why there’s an issue. Fortunately it’s an easy fix. Just specify which type you want by casting one to the other.

Color d_ray_color = do_fire ? (Color)Character.ray_color : Color.white;