{"record":{"id":"e7abf323dd5740ad","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-add-non-persisted-config-object-with-name","errorCode":null,"errorMessage":"Cannot add non-persisted config object with name '${name}'.","messagePattern":"Cannot add non-persisted config object with name '(.+?)'\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorBuildSettings.bindings.cs","lineNumber":175,"sourceCode":"\n        [Obsolete(\"UseParallelAssetBundleBuilding is obsolete and will be removed.\")]\n        [NoAutoStaticsCleanup] // deprecated value-type setting; safe to persist across reload\n        public static bool UseParallelAssetBundleBuilding { get; set; } = false;\n\n        [NativeMethod(\"AddConfigObject\")]\n        static extern ConfigObjectResult AddConfigObjectInternal(string name, Object obj, bool overwrite);\n        public static extern bool RemoveConfigObject(string name);\n        public static extern string[] GetConfigObjectNames();\n        static extern Object GetConfigObject(string name);\n        public static void AddConfigObject(string name, Object obj, bool overwrite)\n        {\n            var result = AddConfigObjectInternal(name, obj, overwrite);\n            if (result == ConfigObjectResult.Succeeded)\n                return;\n            switch (result)\n            {\n                case ConfigObjectResult.FailedEntryExists: throw new Exception(\"Config object with name '\" + name + \"' already exists.\");\n                case ConfigObjectResult.FailedNonPersistedObj: throw new Exception(\"Cannot add non-persisted config object with name '\" + name + \"'.\");\n                case ConfigObjectResult.FailedNullObj: throw new Exception(\"Cannot add null config object with name '\" + name + \"'.\");\n            }\n        }\n\n        public static bool TryGetConfigObject<T>(string name, out T result) where T : Object\n        {\n            result = GetConfigObject(name) as T;\n            return result != null;\n        }\n    }\n}\n","sourceCodeStart":157,"sourceCodeEnd":187,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorBuildSettings.bindings.cs#L157-L187","documentation":"Thrown by EditorBuildSettings.AddConfigObject when the native call returns ConfigObjectResult.FailedNonPersistedObj — the passed UnityEngine.Object is not an asset (not persisted to disk / not tracked by AssetDatabase). Config objects must reference persistent assets so they survive serialization; transient Scene/GameObject instances or 'new' ScriptableObjects are rejected.","triggerScenarios":"Calling AddConfigObject(name, obj, overwrite) where obj is an in-memory object (e.g. new ScriptableObject instance not saved as an asset, a runtime GameObject, a component on an unsaved scene) rather than an AssetDatabase-tracked asset.","commonSituations":"Creating a ScriptableObject with ScriptableObject.CreateInstance<T>() and passing it directly without AssetDatabase.CreateAsset; passing a prefab instance from an open scene rather than the prefab asset.","solutions":["Persist the object first: AssetDatabase.CreateAsset(obj, \"Assets/MyConfig.asset\"); before AddConfigObject.","If the object already exists on disk, resolve the asset reference with AssetDatabase.LoadAssetAtPath rather than a scene instance.","Ensure you pass the asset itself, not an instance/spawn of it."],"exampleFix":"// before\nvar cfg = ScriptableObject.CreateInstance<MyConfig>();\nEditorBuildSettings.AddConfigObject(\"cfg\", cfg, false); // not persisted\n// after\nvar cfg = ScriptableObject.CreateInstance<MyConfig>();\nAssetDatabase.CreateAsset(cfg, \"Assets/MyConfig.asset\");\nAssetDatabase.SaveAssets();\nEditorBuildSettings.AddConfigObject(\"cfg\", cfg, overwrite: true);","handlingStrategy":"validation","validationCode":"if (obj == null || string.IsNullOrEmpty(AssetDatabase.GetAssetPath(obj)))\n    throw new InvalidOperationException(\"obj must be a persisted asset\");\nEditorBuildSettings.AddConfigObject(name, obj, overwrite: true);","typeGuard":"static bool IsPersistedAsset(UnityEngine.Object o) =>\n    o != null && !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(o));","tryCatchPattern":"try { EditorBuildSettings.AddConfigObject(name, obj, false); }\ncatch (Exception ex) when (ex.Message.Contains(\"non-persisted\"))\n{ AssetDatabase.CreateAsset(obj, path); AssetDatabase.SaveAssets(); /* retry */ }","preventionTips":["Always AssetDatabase.CreateAsset + SaveAssets before registering a config object.","Pass asset references loaded via AssetDatabase, not scene/prefab instances.","Check AssetDatabase.Contains(obj) to confirm persistence."],"tags":["editor","build-settings","config","assetdatabase","persistence"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}