From 3802ca557c56ddc776bcb03e652fc132f7ca9fd6 Mon Sep 17 00:00:00 2001 From: Anders Ejlersen Date: Wed, 27 May 2026 19:17:55 +0200 Subject: [PATCH] Validator: Duplicate component validator is now only run on types without DisallowMultipleComponent attribute --- .../GameObjectValidatorDuplicateComponents.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Editor/Validators/GameObject/GameObjectValidatorDuplicateComponents.cs b/Editor/Validators/GameObject/GameObjectValidatorDuplicateComponents.cs index 1ea0509..eaf89a1 100644 --- a/Editor/Validators/GameObject/GameObjectValidatorDuplicateComponents.cs +++ b/Editor/Validators/GameObject/GameObjectValidatorDuplicateComponents.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Reflection; using UnityEngine; using UnityEngine.Pool; @@ -28,7 +30,7 @@ namespace Module.ProjectValidator.Editor } else { - if (count > 1) + if (count > 1 && IsMultipleComponentsAllowed(type)) results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"GameObject has duplicate '{type.Name}' ({count}) components")); type = t; @@ -36,8 +38,13 @@ namespace Module.ProjectValidator.Editor } } - if (count > 1) + if (count > 1 && IsMultipleComponentsAllowed(type)) results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"GameObject has duplicate '{type.Name}' ({count}) components")); } + + private static bool IsMultipleComponentsAllowed(Type type) + { + return type.GetCustomAttribute(true) == null; + } } } \ No newline at end of file