Color32 should implement IEquatable<Color32>

Back in 2017, unity added IEquatable to most structs such as Color, Vector2, Vector2Int, etc…

This greatly speeds up comparing them, since the == operator no longer needs to box them.

But Color32 did not make the cut. Comparing two Color32 values remains expensive and allocates.

I request for Color32 to implement IEquatable, it already has an InternalEquals method that does exactly what is needed (compare the rgba value).

2 Likes

Hey,

Thanks for the suggestion, should be something quick so I’ll take a look at adding it now.
If we are lucky I may be able to get it into Unity 6 :slight_smile:

2 Likes

Awesome, thank you!

Please also consider adding a GetHashCode() method that returns the rgba value. It would make it efficient to add them in sets and use them in dictionaries.

1 Like

Just did, it was needed for the Equals(object) version.

2 Likes

One thing I never understood was why both Color & Color32 were not serializable. I should ask someone internally. Maybe an oversight.

3 Likes

Hey this has landed into 6000.0.3f1 :slight_smile:

2 Likes

Fantastic news! thank you so much @karl_jones

1 Like