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

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

Using this method should take care of it:

You can just use it always, no matter if you’re in Prefab Mode or not. If in Prefab Mode, it should place the GameObject under the Prefab content root.