Renaming a GameObject Clone

spawnObject is just the object to be cloned dragged into a public variable. spawner is a empty gameobejct for where they spawn.

Heres the code, inside a incrementing while loop:

GameObject clone = Instantiate (spawnObject.transform, spawner.transform.position, spawner.transform.rotation) as GameObject; = "spagetti" + Protifuge_Count;

I keep getting this error during run time:

NullReferenceException: Object reference not set to an instance of an object
Debug_Camera+c__Iterator0.MoveNext () (at Assets/IOM/Scripts/Debug_Camera.cs:40)

I’ve tried several different things and don’t know what the problem is…

You are doing Instantiate on a transform and then trying to cast the result to be a GameObject. Instantiate returns the type you pass in, and Transform is not related to GameObject so the result of your cast is null. Cast the return value to Transform and make clone a Transform and it will work as it is.