title: Unity: Instantiating prefab on GameObject - Error Object is null
body: <p>In my Unity game I have a vehicle prefab working with Edy's Vehicle Physics asset. I'm trying to instantiate a chosen vehicle prefab on the position and rotation of a GameObject.</p>
  
  <p>When running my code in my scene to spawn a vehicle I get this error</p>
  
  <blockquote>
    <p>ArgumentException: The Object you want to instantiate is null</p>
    
    <p>ArgumentException: The Object you want to instantiate is null.
    UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:239)
    UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:151)
    UnityEngine.Object.Instantiate[VehicleController] (EVP.VehicleController original, Vector3 position, Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:206)
    VehicleSpawner.spawnVehiclesInFirstGarage () (at Assets/Scripts/VehicleSpawner.cs:44)
    HandleGarage.Start () (at Assets/Scripts/HandleGarage.cs:59)</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/lbonZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lbonZ.png" alt="script"></a></p>
  
  <p>Vehicle Prefab is empty because the vehicle will be chosen by the user in game. (Even if I select a vehicle prefab I still get same error)</p>
  
  <p>My code for instantiating the vehicle prefab on the game object</p>
  
  <pre><code>public EVP.VehicleTelemetry telemetryComponent;
  public EVP.VehicleController vehiclePrefab;
  public GameObject spawnObject;
  
  public void spawnVehiclesInFirstGarage ()
  {
      // Load saved JSON
      string jsonData = SecurePlayerPrefs.GetString ("vehicleNames");
  
      // Convert to Class
      Database loadedData = JsonUtility.FromJson&lt;Database&gt; (jsonData);
  
      // Loop through Owned Vehicles Garage
      for (int i = 0; i &lt; loadedData.vehicleNames.Count; i++) {
  
          // Set up instantiate
          var vehicle = Resources.Load("Prefabs/" + (loadedData.vehicleNames [i]));
          vehiclePrefab = vehicle as EVP.VehicleController;
  
          // Spawn vehicle on game object
          EVP.VehicleController newVehicle = Instantiate(vehiclePrefab, spawnObject.transform.position, spawnObject.transform.rotation) as EVP.VehicleController;
          telemetryComponent.target = newVehicle;
      }
  }
  </code></pre>