What is a good way to instantiate new prefabs via script?

I’m working on a prototype for a tree sim game. The tree is made up of multiple pieces and right now, I want a new piece to appear when I click an existing piece. The new piece’s scale, location, and rotation are based on the piece that was clicked. The pieces are based on a TreePiece prefab. I tried creating a Transform variable in the TreePiece’s script and assigning the TreePiece prefab in the editor. In script, I used Instantiate to create a new piece. The problem is, each new piece’s name adds an extra (clone) to the end (for example: TreePiece(clone)(clone)(clone) ) and weird things are happening like existing pieces re-sizing when I try to resize new pieces. I’m certain this is due to the way I’m trying Insantiate new pieces.

Can someone explain why this might be happening? Is their a better way to instantiate new prefabs via script? Each piece needs to be able to create new pieces and more code will be added to them later as I build the game.

By the way, I’m fairly new to Unity.

Thanks a lot!

try this

public GameObject prefab; //Make sure to set this in the editor

//Call this when you want an object instantiated
void YourFunction() 
{
	GameObject instantiatedGameObject = Instantiate(prefab) as GameObject;
	
	instantiatedGameObject.transform.postion = Vector3.zero; //Or wherever you want it to go.
	//do anything else you want,like change name or quaternion etc.
	
}