{"record":{"id":"e1a1b778694866ff","repo":"Unity-Technologies/UnityCsReference","slug":"asset-objecttoadd-has-a-non-null-path-build-pro","errorCode":null,"errorMessage":"Asset {objectToAdd} has a non-null path. Build profile components should be sub-assets.","messagePattern":"Asset (.+?) has a non-null path\\. Build profile components should be sub-assets\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/BuildProfile/BuildProfile.API.cs","lineNumber":127,"sourceCode":"            }\n\n            // Don't allow duplicates\n            var found = GetComponent<T>();\n            if (found != null)\n            {\n                throw new ArgumentException($\"The component {typeof(T).Name} already exists in the build profile {name}.\");\n            }\n\n            var assetPath = AssetDatabase.GetAssetPath(objectToAdd);\n            if (string.IsNullOrEmpty(assetPath))\n            {\n                objectToAdd.hideFlags |= HideFlags.HideInHierarchy;\n                AssetDatabase.AddObjectToAsset(objectToAdd, this);\n                return;\n            }\n\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);","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/BuildProfile/BuildProfile.API.cs#L109-L145","documentation":"Thrown by BuildProfile.AddComponent<T> when the object to add already has a non-empty asset path (AssetDatabase.GetAssetPath returns a path). Build profile components must be sub-assets of the profile asset itself, not independent assets referenced by path. The code path that handles empty assetPath adds the object as a sub-asset and returns; otherwise it throws InvalidOperationException, noting a future API will support reference-style components.","triggerScenarios":"Passing an object that is already saved as its own asset (e.g. created via AssetDatabase.CreateAsset) to AddComponent. Because GetAssetPath returns the file path, the method refuses and throws.","commonSituations":"Loading an existing .asset ScriptableObject and trying to attach it to a profile; re-parenting an asset that was authored standalone in the project; copying/moving components between profiles that were saved independently.","solutions":["Pass a fresh, unsaved ScriptableObject instance (one with no asset path) so it can be added as a sub-asset.","If you must use an existing asset, first remove it from its current asset file or create a new instance with ScriptableObject.CreateInstance and copy its data.","Await/track the future API referenced by the TODO for reference-style components."],"exampleFix":"// before\nvar existing = AssetDatabase.LoadAssetAtPath<MySettings>(\"Assets/x.asset\");\nprofile.AddComponent(existing); // has a path -> throws\n\n// after\nvar fresh = ScriptableObject.CreateInstance<MySettings>();\nEditorUtility.CopySerialized(existing, fresh);\nprofile.AddComponent(fresh);","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(obj))) { /* has a path; create fresh instead */ }","typeGuard":"static bool IsUnsaved(UnityEngine.Object o) => string.IsNullOrEmpty(AssetDatabase.GetAssetPath(o));","tryCatchPattern":null,"preventionTips":["Only pass freshly created ScriptableObject instances to AddComponent.","Check AssetDatabase.GetAssetPath is empty before adding.","Copy serialized data from an existing asset to a new instance rather than passing the asset directly."],"tags":["unity","buildprofile","assetdatabase","invalidoperationexception","sub-asset"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}