I have solved the script game object references by using code but I cannot find out why the clones of the prefab loose the capsule collider component. Why will unity not keep connections to game objects in scripts on prefabs and save collider components. I feel it makes no sense why this is not able to be done. I can do this with scripting but its stupid its not saving it on the prefab if references are dragged in the inspector into the slots on the scripts.
anyone?
Unity DOES keep references and components when you clone a prefab. You’re clearly removing them yourself. No one will be able to help you without more information related to your scripts and how/when you’re attaching the components.
Another common problem is cloning the wrong object.
I am using instantiate. My code will instantiate the prefab and in the hierarchy it has (clone) in the name next to the instantiated prefab… so I assumed it was a clone. I will add a collider to the prefab object and set up all the connections to other game objects in the public areas on the script threw the inspector by dragging and dropping them into the slots. When I save the prefab changes and go to instantiate the object from code it creates a instantiated object with (clone) next to its name with no collider, it will have the scripts attached but all public fields with references to other scripts and objects will be blank.
Not enough info to know for sure, but what’s possibly happening is:
- Object Foo references other object Bar in the scene.
- Foo gets made into prefab. Prefab does NOT have any reference to Bar, because prefabs can’t reference things inside an individual scene.
- Foo prefab gets instantiated. Still does not have reference to Bar, even though coincidentally in the same scene now, because the reference was already lost.
Does the prefab have those fields filled when you select it in the project hierarchy (not the scene hierarchy)?
ok, so I went back and checked the prefabs and no none have the coliders saved, so I dragged one prefab into the scene and added a box collider and went to save changes to prefab and it dose create it on the clone. I literally went prefab to prefab and selected save changes to prefab on 24 prefabs in my scene and it did not save anything…
The prefab “Apply” button seems to break quite often for me. I suggest creating a fresh copy of the prefab in the scene hierarchy and manually dragging the modified instance back onto the prefab in your project hierarchy.
Not sure if this is your issue, but make sure to either Save Scene or Save Project at some point after doing Apply on prefabs. If you just quit Unity without that, the changes may be lost.
any solution to keeping the references to other game objects and scripts on the prefabs? the fields are blank when the prefab is dragged into the scene or if it is created as a clone too.
That’s not how a prefab works.
It keeps all the links that it can, but links to other objects in the scene are not saved in the prefab because it could be spawned into a scene that does not have those objects.
I confirm this issue, the Collider appears on the clone as expected for a few milliseconds after instantiation then it systematically disappears.
The turn-around for me was to change the prefab’s type reference in the script from GameObject to Collider.
Is this a bug?
i had the same problem. where new instantiate prefab lost is collider, only realise that i deleted the gameObject, and then create a new clone, it will loses it collider, but what i should do is… Instantiate first… then only delete the old gameObject. so that the newew clone will have properties of the old object