I am instantiating and parenting two objects - the first is a Unity primitive and the second is a prefab cube (literally nothing but a cube made into a prefab). The direct instantiation of the primitive works great, but when I try to instantiate the prefab I get NullReferenceException:Object reference not set to an instance of an object
Below is my script:
Vector3 myPosition = new Vector3 (x, Rotator_Prefab.transform.position.y , z); GameObject ball = GameObject.CreatePrimitive (PrimitiveType.Sphere); ball.transform.parent = gameObject.transform; // no problems and gameObject.name gives me the right parent GameObject prefab = Instantiate (Rotator_Prefab, myPosition, Quaternion.identity) as GameObject; prefab.transform.parent = gameObject.transform; // this gives me an error
The error is coming from the prefab still being null after being instantiated. Still it shows up in the scene. Would anyone have any ideas ? - Thank you!
Update: Where the prefab is coming from