{"record":{"id":"a88904698307bab1","repo":"Unity-Technologies/UnityCsReference","slug":"the-object-objecttoremove-path-objecttoremove","errorCode":null,"errorMessage":"The object {objectToRemove} (path: {objectToRemovePath}) is not part of the build profile {path}.","messagePattern":"The object (.+?) \\(path: (.+?)\\) is not part of the build profile (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/BuildProfile/BuildProfile.API.cs","lineNumber":166,"sourceCode":"        /// <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);\n            var objectToRemovePath = AssetDatabase.GetAssetPath(objectToRemove);\n\n            if (objectToRemovePath != path)\n            {\n                throw new ArgumentException($\"The object {objectToRemove} (path: {objectToRemovePath}) is not part of the build profile {path}.\");\n            }\n\n            if (Array.IndexOf(this.requiredComponents, objectToRemove) > -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(objectToRemove);\n        }\n\n        /// <summary>\n        /// Forcibly removes the first occurrence of a component of type T from the build profile.\n        /// For internal use only to accommodate required components.\n        /// </summary>\n        [VisibleToOtherModules]\n        internal void ForceRemoveComponent<T>() where T : UnityEngine.Object\n        {\n            var found = GetComponent<T>();\n            if (found == null)\n            {","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/BuildProfile/BuildProfile.API.cs#L148-L184","documentation":"Thrown by RemoveComponent<T>(T objectToRemove) when the object's asset path does not match the build profile's asset path. The method compares AssetDatabase.GetAssetPath(this) against AssetDatabase.GetAssetPath(objectToRemove); only sub-assets of the same profile .asset file are eligible for removal. A mismatch produces an ArgumentException listing both paths.","triggerScenarios":"Passing an object that lives under a different asset file (or is not a sub-asset of this profile) to RemoveComponent. GetAssetPath returns a different path, so the guard fires.","commonSituations":"Passing a global/shared asset instead of the profile's own sub-asset; mixing up references between profiles; passing a freshly created instance that was never added to the profile.","solutions":["Use GetComponent<T>() to fetch the actual sub-asset belonging to the profile and pass that instance.","Use the parameterless RemoveComponent<T>() which looks up the correct instance internally.","Confirm the object is a sub-asset of the profile via AssetDatabase.GetAssetPath before calling."],"exampleFix":"// before\nprofile.RemoveComponent(someOtherProfileComponent); // different path\n\n// after\nvar own = profile.GetComponent<MySettings>();\nif (own != null) profile.RemoveComponent(own);","handlingStrategy":"validation","validationCode":"string profPath = AssetDatabase.GetAssetPath(profile);\nif (AssetDatabase.GetAssetPath(objectToRemove) == profPath) profile.RemoveComponent(objectToRemove);","typeGuard":"static bool BelongsToProfile(BuildProfile p, UnityEngine.Object o) => AssetDatabase.GetAssetPath(o) == AssetDatabase.GetAssetPath(p);","tryCatchPattern":null,"preventionTips":["Use GetComponent<T>() to obtain the profile's own sub-asset before removal.","Compare asset paths to confirm ownership before calling RemoveComponent(objectToRemove).","Prefer the parameterless RemoveComponent<T>() overload when possible."],"tags":["unity","buildprofile","assetdatabase","path-mismatch","argumentexception"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}