- Home /
Transform position not changing.
I have a first person controller, which is the Player.
Anyway, in my scene there is only one GameObject which will Instantiate the player on the beginning of the game. I can control the player just fine, everything is fine.
However, after debugging a while, I am printing the player's position, and it never changes, even though I clearly move it around. The X position is always 4 (the X where I instantiated it)
Why?
Are you using Debug.Log(transform.position); or Debug.Log(transform.localPosition.x);???. Please, specify put your code or something like that.
Do you ever move it on the x axis? Please post the code which you use to move your GameObject.
Ok, I have used playerObject.transform.localPosition and playerObject.transform.position to track the position of the playerObject, which is a variable linked to the player prefab. The game will Instantiate such prefab into the map. Yes, I do move the player, I mean, it is a first person controller, and I move it all around the map, but the values are the same (equal to the spot where the player was spawned)
i have this too but my bot does update its position when i throw him about. if you have found a solution please let us know
It's a really old question (almost a year) and it seems the OP has abandoned his question. Anyway, i think he's accessing the prefab ins$$anonymous$$d of the Instantiated object. If you have a variable that holds a prefab reference you would use it to instantiate one of these objects and Instantiate returns the reference to the new created instance. If you check the position of the prefab it will always stay the same.
@jimjim: without knowing the actual code and setup fo your scene It's just guessing. You should start a seperate question since this one seems to be dead. Also don't post comments as Answers....
Answer by idiot333 · Feb 26, 2015 at 08:11 PM
It is about Instantiating an object from another object. It's not about transform or anything. It will not work if your instance is not currently present in the scene. BE CAREFULL FROM WHERE YOU PROVIDE THE REFERENCE IN THE INSPECTOR.
if you provide reference(drag and drop the instance of the gameObject) from the HIERARCHY then it's gonna work fine because the object is not null null and is still present in the scene.
if you drag and drop from the prefab in order to provide reference to the gameobject then it will not work if the object not present in the scene ie reference is null.
NOTE: my answer might contain some mistakes as i just started in unity. But That is what worked for me.
Thanks
Answer by ercu · Apr 02, 2015 at 09:23 PM
If you change position on Awake it won't effect. Try changing position on Start.