0
votes
Transform child = GameObject.FindWithTag("state").transform;
    child.name = first_guy+""; child.tag = first_guy+"";
    GameObject  child_dup = Instantiate( child, new Vector3(0,0,0),Quaternion.identity) as GameObject; 
    Debug.Log (child_dup.name);

The above code gives me error, "NullReferenceException: Object reference not set to an instance of an object". Is this because I am trying to instantiate a local variable? How to duplicate a gameobject in run time?

1
If you are trying to post code, you need 4 spaces before each line of code.Draco18s no longer trusts SE
I was fighting for that :D It was giving error..Distraction Arrestor
Is first_guy some string variable you have set?WearyWanderer

1 Answers

2
votes

Your problem is that you are trying to instantiate a Transform which is a component and cannot be instantiated, as it must be attached to a GameObject.

Instantiate( child.gameObject, ...)