{"record":{"id":"ea59328aa4723007","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-convert-the-gameobject-0-with-root-tran","errorCode":null,"errorMessage":"Cannot convert the GameObject '{0}' with root transform of type {1} with a Prefab asset with root transform of type {2}. Transform types must match.","messagePattern":"Cannot convert the GameObject '(.+?)' with root transform of type (.+?) with a Prefab asset with root transform of type (.+?)\\. Transform types must match\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2361,"sourceCode":"        internal static void ThrowIfInvalidArgumentsForConvertToPrefabInstance(GameObject plainGameObject, GameObject prefabAssetRoot, bool checkValidAsset, InteractionMode mode)\n        {\n            if (plainGameObject == null)\n                throw new ArgumentNullException(nameof(plainGameObject));\n\n            if (prefabAssetRoot == null)\n                throw new ArgumentNullException(nameof(prefabAssetRoot));\n\n            if (IsPartOfNonAssetPrefabInstance(plainGameObject))\n                throw new InvalidOperationException(string.Format(\"Input '{0}' is not a plain GameObject, it is already a Prefab instance. Use ReplacePrefabAssetOfPrefabInstance() instead.\", plainGameObject.name));\n\n            if (EditorUtility.IsPersistent(plainGameObject))\n                throw new ArgumentException(\"Input is from a Prefab asset, this is not supported. Input GameObject: \" + plainGameObject.name, nameof(plainGameObject));\n\n            if (checkValidAsset)\n                ThrowIfInvalidAssetForReplacePrefabInstance(prefabAssetRoot, mode);\n\n            if (plainGameObject.transform.GetType() != prefabAssetRoot.transform.GetType())\n                throw new InvalidOperationException(string.Format(\"Cannot convert the GameObject '{0}' with root transform of type {1} with a Prefab asset with root transform of type {2}. Transform types must match.\", plainGameObject.name, plainGameObject.transform.GetType().Name, prefabAssetRoot.transform.GetType().Name));\n\n            // Prefab Mode and EditPrefabContents scope handling\n            if (PrefabStageUtility.IsGameObjectThePrefabRootInAnyPrefabStage(plainGameObject) || (EditorSceneManager.IsPreviewSceneObject(plainGameObject) && plainGameObject.transform.parent == null))\n                throw new InvalidOperationException(\"Replacing the root GameObject in a Prefab with a Prefab instance is not supported since it will break all overrides for existing instances of this Prefab, including their positions and rotations.\" + plainGameObject.name);\n\n            if (plainGameObject.hideFlags.HasFlag(HideFlags.DontSaveInEditor) || plainGameObject.transform.hideFlags.HasFlag(HideFlags.DontSaveInEditor))\n                throw new ArgumentException(\"Input GameObject is using the HideFlags.DontSaveInEditor flag which is not supported when converting to Prefab instance: GameObject: \" + plainGameObject.name, nameof(plainGameObject));\n\n            if (mode == InteractionMode.UserAction)\n            {\n                // Recording undo does not handle missing scripts\n                var gameObjectsWithInvalidScript = FindGameObjectsWithInvalidComponent(plainGameObject);\n                if (gameObjectsWithInvalidScript.Count > 0)\n                    throw new InvalidOperationException(string.Format($\"Cannot convert the GameObject when it has a missing script. GameObject '{gameObjectsWithInvalidScript[0].name}' has a missing script. This is not supported by the Undo system. Use InteractionMode.AutomatedAction instead.\"));\n            }\n        }\n\n        public static void ConvertToPrefabInstance(GameObject plainGameObject, GameObject prefabAssetRoot, ConvertToPrefabInstanceSettings settings, InteractionMode mode)","sourceCodeStart":2343,"sourceCodeEnd":2379,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2343-L2379","documentation":"Thrown by ThrowIfInvalidArgumentsForConvertToPrefabInstance when plainGameObject.transform.GetType() != prefabAssetRoot.transform.GetType(). The root Transform of the plain GameObject and the target Prefab asset must be the same type (both Transform or both RectTransform). A mismatch — e.g. converting a 3D object (Transform) to a UI Prefab (RectTransform) — would corrupt the hierarchy.","triggerScenarios":"Converting a 3D scene object into a UI Canvas Prefab, or a UI element into a 3D Prefab. Using a Prefab asset whose root has a custom Transform subclass against a plain GameObject with a base Transform.","commonSituations":"Generic conversion tool that doesn't differentiate UI from 3D Prefabs. Art pipeline that changes root structure between Prefab versions.","solutions":["Match the Transform type: use a UI Prefab asset for UI objects (RectTransform) and a 3D Prefab for 3D objects (Transform).","Guard before calling: if (plainGameObject.transform.GetType() != prefabAssetRoot.transform.GetType()) skip or warn.","Re-parent or restructure the plain GameObject so its root Transform type matches the target Prefab."],"exampleFix":"// before\nPrefabUtility.ConvertToPrefabInstance(plainGo, uiPrefabAsset, settings, mode);\n// plainGo root is Transform, uiPrefabAsset root is RectTransform\n\n// after\nif (plainGo.transform.GetType() == uiPrefabAsset.transform.GetType())\n    PrefabUtility.ConvertToPrefabInstance(plainGo, uiPrefabAsset, settings, mode);\nelse\n    Debug.LogWarning(\"Transform type mismatch; cannot convert.\");","handlingStrategy":"validation","validationCode":"if (plainGameObject.transform.GetType() != prefabAssetRoot.transform.GetType())\n{\n    Debug.LogError($\"Transform type mismatch: {plainGameObject.transform.GetType().Name} vs {prefabAssetRoot.transform.GetType().Name}\");\n    return;\n}\nPrefabUtility.ConvertToPrefabInstance(plainGameObject, prefabAssetRoot, settings, mode);","typeGuard":"static bool TransformTypesMatch(GameObject go, GameObject asset)\n{\n    return go != null && asset != null\n        && go.transform.GetType() == asset.transform.GetType();\n}","tryCatchPattern":null,"preventionTips":["Maintain separate Prefab catalogs for UI (RectTransform) and 3D (Transform) assets.","Add a transform-type check to generic conversion utilities."],"tags":["prefab","transform-type","rect-transform","argument-validation","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}