Instantiate creates object at wrong position


I got the following code:

using UnityEngine;
using System.Collections;

public class PlaceTower : MonoBehaviour {

	public GameObject towerPrefab;
	private GameObject tower;

	void OnMouseUp () {
		if (canPlaceTower ()) {
			tower = (GameObject) 
				Instantiate(towerPrefab, transform.position, Quaternion.identity);

	private bool canPlaceTower(){
		return tower == null;

which is supposed to spawn a tower once you click on the white cube on the terrain: Screenshot - aceb98fd0a1d79b62bcba6e48a7db4b6 - Gyazo

Tower position:

The tower should be placed on the exact same position as the cube which it apparently is since the spawned tower has the same coordinates as the white cube but the tower is located somewhere else upp in the air.

Does someone know what the issue could be?

I had the same problem and found out my prefab transform had a default position in it’s transform which was causing the offset. You would think a prefab would always be at exactly where you spawn them but they actually add their transform position to the position you give them when instantiating. (To fix it just change the prefab transform position to 0,0,0).

The issue is your OpenSpot is located at y = 0 which is in the air, relative to your ground which has some negative y value. I suggest dragging the OpenSpot down until it hits the ground and then try spawning again.

I just run into similar problem with wrong instantiate position ,
might not be the same issue as yours ,

I checked all hierachy are set to (0,0,0)
and also all the animation begin with (0,0,0)

that solved my problem , which caused by editing the animation at non origin(0,0,0) position and the animator saved the displacement value

besure you click “apply change to Prefab” from “GameObject” menu after changing all position to 0,0,0

good luck!

in my case i was initialise coordinates before use base class of instance. and and this led to different coordinates.maybe someone find here solve problem