Search Issue Tracker
By Design
Votes
0
Found in
5.3.0f4
Issue ID
756919
Regression
No
If prefab is instantiated with PrefabUtility.InstantiatePrefab children is not found using GetComponentsInChildren<Transform>
How to reproduce:
1. Open 'Test Scene' in the attached project
2. Delete 'child' object
3. Press play in editor. (child object is instantiated at runtime because it is missing.)
4. Press stop in editor. (child object is instantiated at edit time using prefab instantiation, again because it is missing).
5. Press play in editor. (somehow a new child object appears at runtime, with 'child 1' name, even tho it should not, because a child object was present).
6. Press stop in editor. (the 'child 1' object appears as a prefab this time, because at edit time the code instantiates an object using prefab instantiation, but this should not happen because the object 'child' was present in children of 'parent')
Workaround: If Object.Instantiate is used instead of PrefabUtility.InstantiatePrefab
(in the AddChild method), this behaviour of 'child 1' appearing is not
happening. As then GetComponentsInChildren<Transform> finds children
BY DESIGN: The reason the extra objects appears is because the altered named of the first added GameObject is not recorded using PrefabUtility.RecordPrefabInstancePropertyModifications() (in this case you would pass the gameObject as the argument), so Unity registers it's name as "child 1" rather than "child". Since the script is checking for "child" it will never find any gameObjects, and therefore it keeps instantiating them.
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
Add comment