gameObject.SetParent(null); results in error, does not deparent.

Just upgraded to 2022.2 beta8.3023

Calling .SetParent(null) during OnEnable results in this error message and failure to deparent:

Setting the parent of a transform which resides in a Prefab instance is not possible (GameObject: 'CameraGroup').
UnityEngine.StackTraceUtility:ExtractStackTrace ()
DetachOnEnable:OnEnable () (at Assets/+ProjectAssets/Scripts/Utility/DetachOnEnable.cs:7)

The object in question is indeed part of a prefab in edit mode, but it is my understanding that prefabs are unpacked upon entering playmode and this should not be occurring.

Looks like a regression because I do the same thing on 2020.3 and it works fine

That is the expected behaviour over four major versions i’ve seen/used yea :slight_smile:

I have the same error when reparenting in Awake() since I upgraded from 2022.1 to 2022.2.

Also made a post about it a few days ago in the prefab forum:

And created a bug report for it: IN-17572

1 Like