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
- Warning of an unknown Script missing is logged when selecting VFX in Play Mode
- Vertical and horizontal scrollbars appear and disappear when dragging an attribute to a different position within the Shader Graph Hierarchy
- AudioSource.PlayDelayed() does not work with Audio Random Containers
- Compatible with the VFX Graph Shader Graph can't be dragged and dropped into the "Output" block from the Project window
- [Silicon] Freeze/crash on BrotliDecoderDecompressStream when using System.IO.Compression.BrotliDecoder.TryDecompress
Add comment