Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

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

Discussion in '2022.2 Beta' started by JJRivers, Sep 13, 2022.

  1. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    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.
     
  2. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    218
    Looks like a regression because I do the same thing on 2020.3 and it works fine
     
  3. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    That is the expected behaviour over four major versions i've seen/used yea :)
     
  4. moritz_jaeger

    moritz_jaeger

    Joined:
    Jun 15, 2015
    Posts:
    7
    DevDunk likes this.