Search Unity

Instantiate game object via editor script and attach it to root object of a prefab

Discussion in 'Prefabs' started by Cosmonaut72, Jul 29, 2019.

  1. Cosmonaut72

    Cosmonaut72

    Joined:
    Nov 16, 2017
    Posts:
    9
    Hi,

    I was encountering issues where I would instantiate a GameObject within the new prefab editor sub-scene. Any attempt to move the transform of this object however and it got deleted automatically.
    I managed to deduce it was because it was creating the object on the same tier as the root prefab object and if I manually child it to the root, it would work fine.
    Is there a way to alter my editor script so that it knows it is within a prefab scene and automatically search for and parent itself to the root node?

    Thanks
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892