diff --git a/sources/core/Stride.Core/DisplayAttribute.cs b/sources/core/Stride.Core/DisplayAttribute.cs index ac65469575..f1aa958319 100644 --- a/sources/core/Stride.Core/DisplayAttribute.cs +++ b/sources/core/Stride.Core/DisplayAttribute.cs @@ -82,7 +82,7 @@ public DisplayAttribute(string name = null, string category = null) /// Gets the hue of a color that is used in the UI. /// /// If not null, this value must be in the range [0, 360]. - public float? CustomHue { get; set; } + public float CustomHue { get; set; } = -1f; /// /// Gets or sets whether to expand the control representing the associated object in the UI. diff --git a/sources/presentation/Stride.Core.Presentation/Core/Utils.cs b/sources/presentation/Stride.Core.Presentation/Core/Utils.cs index c153207de5..6cb2af02cf 100644 --- a/sources/presentation/Stride.Core.Presentation/Core/Utils.cs +++ b/sources/presentation/Stride.Core.Presentation/Core/Utils.cs @@ -32,7 +32,12 @@ public static Color4 GetUniqueColor(this Type type) var displayAttribute = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute(type); var hash = displayAttribute?.Name.GetHashCode() ?? type.Name.GetHashCode(); hash = hash >> 16 ^ hash; - var hue = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute(type)?.CustomHue ?? hash % 360; + + var hue = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute(type)?.CustomHue ?? -1; + if(hue is < 0 or > 360) + { + hue = hash % 360; + } return new ColorHSV(hue, 0.75f + (hash % 101) / 400f, 0.5f + (hash % 151) / 300f, 1).ToColor(); } }