{"record":{"id":"5225243608f4c191","repo":"Unity-Technologies/UnityCsReference","slug":"the-component-typeof-t-name-is-required-and-can","errorCode":null,"errorMessage":"The component {typeof(T).Name} is required and cannot be removed from the build profile {name}.","messagePattern":"The component (.+?) is required and cannot be removed from the build profile (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/BuildProfile/BuildProfile.API.cs","lineNumber":143,"sourceCode":"\n            // TODO: Future API will support build profile components as reference.\n            throw new InvalidOperationException($\"Asset {objectToAdd} has a non-null path. Build profile components should be sub-assets.\");\n        }\n\n        /// <summary>\n        /// Removes the first occurence of a component of type T from the build profile.\n        /// </summary>\n        public void RemoveComponent<T>() where T : UnityEngine.Object\n        {\n            var found = GetComponent<T>();\n            if (found == null)\n            {\n                Debug.LogWarning($\"The component {typeof(T).Name} does not exist in the build profile {name}. \");\n                return;\n            }\n\n            if (Array.IndexOf(this.requiredComponents, found) > -1)\n                throw new ArgumentException($\"The component {typeof(T).Name} is required and cannot be removed from the build profile {name}.\");\n\n            AssetDatabase.RemoveObjectFromAsset(found);\n        }\n\n        /// <summary>\n        /// Removes a specific component from the build profile.\n        /// </summary>\n        /// <param name=\"objectToRemove\">Object to remove.</param>\n        /// <exception cref=\"ArgumentNullException\">objectToRemove is null.</exception>\n        /// <exception cref=\"ArgumentException\">objectToRemove is not part of the build profile.</exception>\n        public void RemoveComponent<T>(T objectToRemove) where T : UnityEngine.Object\n        {\n            if (objectToRemove == null)\n            {\n                throw new ArgumentNullException(nameof(objectToRemove), \"The object to remove cannot be null.\");\n            }\n\n            var path = AssetDatabase.GetAssetPath(this);","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/BuildProfile/BuildProfile.API.cs#L125-L161","documentation":"Thrown by the parameterless RemoveComponent<T>() when the located component is listed in the profile's requiredComponents array. Required components are protected from removal; the method uses Array.IndexOf(this.requiredComponents, found) > -1 to detect this and throws ArgumentException. Use ForceRemoveComponent<T>() (internal) to bypass the guard.","triggerScenarios":"Calling RemoveComponent<T>() on a type that is registered as required for the build profile (e.g. a platform-specific required component). The component is found, but it is in the requiredComponents array.","commonSituations":"Attempting to clean up or reset a profile and removing a component the platform marks as mandatory; scripting logic that tries to remove all components generically; misunderstanding which components are required for a given platform.","solutions":["Do not remove the required component — instead update its fields/config in place.","If removal is genuinely necessary from internal module code, use ForceRemoveComponent<T>() (internal, VisibleToOtherModules).","Inspect profile.requiredComponents to know which types are protected before attempting removal."],"exampleFix":"// before\nprofile.RemoveComponent<RequiredSettings>(); // throws\n\n// after\n// Update the required component in place instead of removing it.\nvar s = profile.GetComponent<RequiredSettings>();\ns.someField = newValue;","handlingStrategy":"validation","validationCode":"var existing = profile.GetComponent<T>();\nif (existing != null && Array.IndexOf(profile.requiredComponents, existing) < 0) profile.RemoveComponent<T>();","typeGuard":"static bool IsRemovable<T>(BuildProfile p) where T : UnityEngine.Object { var c = p.GetComponent<T>(); return c != null && Array.IndexOf(p.requiredComponents, c) < 0; }","tryCatchPattern":null,"preventionTips":["Inspect profile.requiredComponents before removing.","Prefer updating required components in place over removing them.","Filter required components out of bulk-cleanup loops."],"tags":["unity","buildprofile","required-component","argumentexception","removal"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}