Attach object when NOT in Hierarchy

Hey, I’m new to Unity, which makes me pretty bad at it. I’ll try to explain my problem as good as I can.

I have an object saved, which I will spawn when a certain thing happens. I want to attach an object to that object, but it only works when that object is out in the Hierarchy. How do i solve this?


When the object is saved, but not out in the Hierarchy. (doesnt work to attach)

When the object is out in the Hierarchy, it’s possible to attach them.

How do I fix this? Is it a way?

This cannot be done.

This is because you can instantiate a prefab in any scene. Unity has no guarantee that the hierarchy object will exist at runtime. You can link in another prefab. Or you can use GameObject.Find via script to get an instance at runtime.