- Home /
Assigning a prefab to itself.
Hey, The problem I'm having is I've made an inventory and that's all working fine. But I'm trying to make it so I can drop items onto the floor. So what I'm trying to do is have an ItemData class that gets put into the inventory collection and that ItemData class contains a baseItem GameObject were I can assign the prefab to itself. But when I do it unity thinks it's meant to be a reference to itself. Is there anyway to break the reference at start up so it's just the original prefab.
Answer by doublethink · Jan 16, 2013 at 11:10 PM
I believe your issue is due to a circular reference. Add the static
modifier to the member GameObject if you really need to directly reference the prefab. A better design would to have a string member that contains the name of the prefab. You can then use Resources.Load("prefabName")
and Instantiate
to re-create the object during runtime.
See http://docs.unity3d.com/Documentation/Manual/LoadingResourcesatRuntime.html