Object instantiate as clone

Hello, When I instantiate an object with my script, the object instantiate as a child of the object that had the script, how can I fix that ?

public void RemoveEyepiece()
    {
        if (scope.EyepieceName == "Plossl10mm")
        {
            Instantiate(Plossl10mm, eyepiecesdrop);
            pickupeyepieces.EyepiceName = "";
            pickupeyepieces.EyepieceDesign = "";
            pickupeyepieces.EyepieceFocalLenght = 0;
            pickupeyepieces.EyepieceFOV = 0;
            scope.EyepieceName = pickupeyepieces.EyepiceName;
            scope.EyepiceFocalLenght = pickupeyepieces.EyepieceFocalLenght;
            scope.EyepieceFOV = pickupeyepieces.EyepieceFOV;
            scope.EyepieceDesign = pickupeyepieces.EyepieceDesign;
            scope.EyepieceName = pickupeyepieces.EyepiceName;
        }
    }

The second argument of the Instantiate function is the transform that you want the clone to be a child of.

1 Like

I still have a problem, the object instantiate but it is named “Plossl10mm(Clone)” and for some reason it absolutely need to be “Plossl10mm” or the script will not work

Also for some reason, the player can’t pîck up the eyepiece once removed from the scope even if it instantiates as a prefab and my script to pick up objects work with component so it shouldn’t happen.

Not Tested but try this.

public void RemoveEyepiece()
    {
        if (scope.EyepieceName == "Plossl10mm")
        {
            GameObject clone =  Instantiate(Plossl10mm, eyepiecesdrop)as GameObject;
            pickupeyepieces.EyepiceName = "";
            pickupeyepieces.EyepieceDesign = "";
            pickupeyepieces.EyepieceFocalLenght = 0;
            pickupeyepieces.EyepieceFOV = 0;
            scope.EyepieceName = pickupeyepieces.EyepiceName;
            scope.EyepiceFocalLenght = pickupeyepieces.EyepieceFocalLenght;
            scope.EyepieceFOV = pickupeyepieces.EyepieceFOV;
            scope.EyepieceDesign = pickupeyepieces.EyepieceDesign;
            scope.EyepieceName = pickupeyepieces.EyepiceName;
            clone.name = Plossl10mm;
        }
    }