Search Issue Tracker
By Design
Votes
0
Found in
2018.3.0a6
2018.3.6f1
2019.1.0a1
2019.2.0a1
Issue ID
1128227
Regression
No
Prefab instance with a script that automatically sets the parent of it creates a duplicate of itself after exiting Prefab mode
How to reproduce:
1. Download extract and open attached project (1128227repro.zip)
2. Open 'SampleScene'
3. Create an empty object and name it 'parent'
4. Create an instance of 'GameObject' Prefab (object 'parent' will automatically be the parent of it)
5. De-parent the 'GameObject' prefab instance
6. Enter and exit 'GameObject' prefab mode
Expected results: The hierarchy is unchanged or 'GameObject' is the child of object 'parent'
Actual results: 'GameObject' is left unchanged but another 'GameObject' is created as a child of 'parent' with a broken connection to the prefab
Reproducible with: 2018.3.6f1, 2019.1.0b4, 2019.2.0a6
Note: If the 5th step is missed, the Prefab instance connection to the Prefab simply breaks.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Unity Hub closes with no "Project is currently open" window when selecting an already open project from the Projects list
- The Hub freezes indefinitely when copy/pasting a lot of characters in the “Set project display name” Hub window since it has no character limit
- Inconsistent “Favorites” icon highlight in Unity Hub
- "Could not connect project. Try again" Hub error is not informative/does not inform the user with the reason why it failed when connecting a project to cloud with a name that's too long
- “Create and publish WebGL builds” link leads to “Sorry about that, we can't find the page you're looking for.” page
Resolution Note (2019.2.X):
This is a script error. The root of the prefab is moved out of the Prefab Mode when Start() from SetParentInEditor.cs is called due to the script is using ExecuteInEditMode.
To fix this make sure your script handles PrefabMode. This can be done by ensuring you do not change the parent if the gameobject is part of a PreviewScene (which is used for various tools and for Prefab Mode):
bool isPreviewSceneObject = EditorSceneManager.IsPreviewSceneObject(gameObject);
if (!isPreviewSceneObject && !string.IsNullOrEmpty(parentName) && UnityEditor.Selection.activeInstanceID == gameObject.GetInstanceID()) {
if (!transform.parent) transform.SetParent(parentName.GetParentObjectByName());
}