I have a GameObject prefab that I Instantiate into my scene. It Instantiates a different GameObject (sometimes multiple) into the scene as a child. The object also can Instantiate another instance of itself. The issue is when I Instantiate the instance of itself it also instantiates the other if previously instantiated. It basically uses the current object, and not the original prefab.
Here’s a pseudo example:
public class MyObject : MonoBehaviour
{
public MyObject myObject; //Prefab from editor
public OtherObject otherObject; //Prefab from editor
MyObject link; //Storage for Instantiated MyObject
OtherObject otherLink; //Storage for Instantiated OtherObject
void AddMyObject()
{
link = Instantiate(myObject, new Vector3(0, 0, 0), Quaternion.identity, this.transform);
}
void AddOtherObject()
{
otherLink= Instantiate(otherObject, new Vector3(0, 0, 0), Quaternion.identity, this.transform);
}
}
If I call AddOtherObject() then call AddMyObject() my new instance of MyObject contains an instance of the otherObject. It’s using the current MyObject instead of the prefab. I need it to use the prefab without the OtherObject instanced.
In the editor it says Gutter(Clone)(GutterScript) it should say Gutter(GutterScript) and works if I edit the value in the editor.
Any ideas?