strange nullreference exeption

I get the following error on line 4
If the instantiate works fine why would I get null reference ?
even if I simply try to do Debug.Log(ff.name) I get null reference.

            foreach (PERSONNEL p in GameControl.control.cities[GameControl.control.cityindex].centralOffice.personnel)
            {
               GameObject ff =  Instantiate(operator_prefab, p.obj_pos, transform.rotation) as GameObject;
                ff.name = "ppp";
                       }

‘as’ returns null if the case doesn’t work. I’m assuming operator_prefab is not a GameObject, so that’s not the type Instantiate’s returning.

Always use the unsafe casts:

GameObject ff =  (GameObject) Instantiate(operator_prefab, p.obj_pos, transform.rotation);

rather than the safe ones:

GameObject ff =  Instantiate(operator_prefab, p.obj_pos, transform.rotation) as GameObject

when you’re sure about the type the object should be. Then you get the error on the correct line if you’re wrong, rather than later, as you’ve experienced now.