I’ve been developing in Unity for years and I can’t believe I’m stumped by something that should be very simple. I want to instantiate a GameObject and place it at a world position but I also want to parent it to a twisted mess of a tree of GameObjects (all different rotations/scales of the objects in the tree). Seems simple enough. The Unity Editor can figure it out. I can spawn the object but not parent it, run it in the editor, hit pause and then drag the GameObject to the node I want and, lo and behold, it stays put.
But programmatically? That’s been a nightmare. I’ve tried setting the parent transform right IN the Instantiate call. I’ve tried transform.SetParent() with a true for keepworldposition. I’ve tried TransformPoint. I’ve tried a half dozen other things besides this too, and the object keeps moving on me. I do not know the relative position for that complex transform but I also don’t want the GameObject to not be parented because I want it deleted when the root is deleted.
Is it even possible to parent a GameObject to somewhere in the bottom of a twisted mess of an object tree but make sure it starts off at an absolute world position? Of course I don’t care that the object would move with the parent. In fact, the parent won’t be moving. I can’t even set it’s initial position properly.