{"record":{"id":"2b89ea1c041d4e0b","repo":"Unity-Technologies/UnityCsReference","slug":"duplicating-assets-is-unsupported-by-this-function","errorCode":null,"errorMessage":"Duplicating Assets is unsupported by this function. Use AssetDatabase.CopyAsset to duplicate Assets.","messagePattern":"Duplicating Assets is unsupported by this function\\. Use AssetDatabase\\.CopyAsset to duplicate Assets\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GameObjectUtility.bindings.cs","lineNumber":187,"sourceCode":"        {\n            return DuplicateGameObjects(gameObjects, true);\n        }\n\n        public static GameObject[] DuplicateGameObjects(GameObject[] gameObjects, bool recordUndo)\n        {\n            if (gameObjects == null)\n                throw new System.ArgumentNullException(\"gameObjects array is null\");\n\n            if (gameObjects.Length == 0)\n                return Array.Empty<GameObject>();\n\n            foreach (GameObject go in gameObjects)\n            {\n                if (go == null)\n                    throw new System.ArgumentNullException(\"GameObject in gameObjects array is null\");\n\n                if (EditorUtility.IsPersistent(go))\n                    throw new System.ArgumentException(\"Duplicating Assets is unsupported by this function. Use AssetDatabase.CopyAsset to duplicate Assets.\");\n            }\n\n            return DuplicateGameObjects_Internal(gameObjects, recordUndo);\n        }\n\n        public static GameObject DuplicateGameObject(GameObject gameObject)\n        {\n            return DuplicateGameObject(gameObject, true);\n        }\n\n        public static GameObject DuplicateGameObject(GameObject gameObject, bool recordUndo)\n        {\n            if (gameObject == null)\n                throw new System.ArgumentNullException(\"gameObject is null\");\n\n            if (EditorUtility.IsPersistent(gameObject))\n                throw new System.ArgumentException(\"Duplicating Assets is unsupported by this function. Use AssetDatabase.CopyAsset to duplicate Assets.\");\n","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GameObjectUtility.bindings.cs#L169-L205","documentation":"DuplicateGameObjects rejects persistent objects (assets) because runtime duplication semantics differ from asset duplication; EditorUtility.IsPersistent returns true for assets and the API throws ArgumentException directing you to AssetDatabase.CopyAsset instead. This guard prevents accidental in-place asset cloning that would bypass import/serialization.","triggerScenarios":"Passing a prefab/asset GameObject (e.g. loaded via AssetDatabase.LoadAssetAtPath) into DuplicateGameObjects; selecting an asset in the Project window and triggering duplicate-via-this-API; batch operations that mix scene objects and assets.","commonSituations":"Editor tool that duplicates 'objects' generically without distinguishing scene Hierarchy vs Project assets; copy-paste from scene duplication code applied to assets.","solutions":["For assets, use AssetDatabase.CopyAsset(sourcePath, destPath) instead.","Pre-filter the array to exclude persistent objects before calling DuplicateGameObjects.","Instantiate an asset into the scene first (Object.Instantiate) if you want a scene copy, then duplicate."],"exampleFix":"// before\nGameObjectUtility.DuplicateGameObjects(new[] { prefabAsset });\n\n// after\nAssetDatabase.CopyAsset(AssetDatabase.GetAssetPath(prefabAsset), destPath);","handlingStrategy":"validation","validationCode":"var sceneOnly = gameObjects.Where(go => !EditorUtility.IsPersistent(go)).ToArray();\nif (sceneOnly.Length == 0) return Array.Empty<GameObject>();\nreturn GameObjectUtility.DuplicateGameObjects(sceneOnly, recordUndo);","typeGuard":"static bool IsSceneObject(GameObject go) => go != null && !EditorUtility.IsPersistent(go);","tryCatchPattern":null,"preventionTips":["Branch on EditorUtility.IsPersistent before duplicating.","Use AssetDatabase.CopyAsset for Project-window assets.","Keep scene-duplication and asset-copy code paths separate."],"tags":["gameobject","asset","argument","editor-scripting","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}