I have a component called Item which holds a reference to a Prefab. The GameObject this component is attached to is that Prefab, so it’s a variable which points to its own Prefab.
The problem is that when I instantiate this prefab, the variable which references the prefab seems to actually change and point to the instance of the instantiated GameObject instead of referencing the Prefab.
I’m assuming this is because it’s actually referencing itself and not the prefab object? I have no idea, but is there any way to solve this problem?
I believe this is intended behaviour. Look at it this way: Your prefab is a GameObject that holds a component, and that component has a field that points to the GameObject that the component is attached to. When you instantiate the prefab, you create a copy of that object, and so the copy also contains a component that points to its own GameObject. Make sense?
If you want a long-term reference to your prefab so you can easily instantiate it at will, you should use a different object to keep a reference to it (also make sure you’re not assigning the newly instantiated copy to your field).