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
- “[Worker0] Could not generate preview image“ error when opening macOS native plugin in the Inspector with Architecture to build for set to ARM 64-bit
- [iOS] Application.absoluteURL is empty on Awake/Start when opening via deep link with Splash Screen disabled
- Crash on MemoryManager::Deallocate when rapidly calling Addressables.LoadAssetAsync
- Crash on physx::shdfnd::atomicIncrement when adjusting values on a character controller component after entering Play mode in Prefab edit mode
- [Rendering Debugger] [NewInputSystem] Debug Overlays in Play mode throws InvalidOperationException when using New Input System
Add comment