- Home /
GameObject position and localPosition not changing in hiearchy, only in script.
I have a prefab i instantiate, and when i change its position and local position to 0,0 it doesn't seem to change in hierarchy view in editor. I have a debug system that prints out values to a gui text object and it says the local position before and after is 0,0. But in the editor it is a random huge value. Why would this be?
I'm using this code to change its positions:
     debugGText.permDebug("pos: (" + transform.position.x + "," + transform.position.y + ")");
     transform.position = Vector3.zero;
     debugGText.permDebug("pos(after): (" + transform.position.x + "," + transform.position.y + ") and localPos: (" + transform.localPosition.x + "," + transform.localPosition.y + ")");
     transform.localPosition.Set(0,0,0);
     debugGText.permDebug("localPos: (" + transform.localPosition.x + "," + transform.localPosition.y + ")");
This code works fine with no compile errors and print sout the location to the gui text object. Here is a screenshot of this in the editor window(I highlighted notable parts): There are no null reference exceptions and the script is on the gameobject i wnat to modify. Notice that the gameObjects's transform only has localPosition and not normal position. Why is this? It is not a child of another object....Just a prefab. 
$$anonymous$$y guess would be that something is changing it after your debug logging - where is that happening at the moment?
This script that's printing values, which object is it attached to?
- The values you're printing refer to whatever object the script is attached to. 
- The values in the inspector refer to whatever object you have selected in the editor. 
If those two aren't the same object, confusion might result.
Nope. I don't modify the position of the gameObject anywhere else.... Here is my scripts on justPaste.it.
Hmmm, well your transform.localPosition.Set(0,0,0) probably isn't doing anything as transform.localPosition returns a copy of its position I believe. But clearly the position appears to be Vector3.zero in any case. Which makes sense as it has no parent right?
Answer by whydoidoit · May 23, 2012 at 12:12 AM
In you full script you have this code:
  private void updateTextPos()
     {
         Vector3 worldLocation = mainCam.ScreenToWorldPoint(buildGuiLocation);
         labelOfBuilder.transform.position = worldLocation;
     }
But labelOfBuilder is a component on the same game object as the Builder script, so it moves the builder to that location, hence your changed coordinates.
Nice catch! how did i forget that?? I forgot to attach it to a child gameObject for this part of my implimentation.
Just one of those - when you've exhausted the obvious and you don't know the code you see it with different eyes :)
Hi, @whydoidoit. I'm struggling with a similar problem for months! Since you catch the problem here, would you $$anonymous$$d to take a look at my question? Thank you in advance.
Answer by Giblon12 · Nov 26, 2020 at 11:40 AM
https://companynamegenerator.net https://companynamegenerator.net/page/youtube-name-generator https://companynamegenerator.net/page/restaurant-name-generator-ideas https://companynamegenerator.net/page/podcast-name-generator https://companynamegenerator.net/page/event-festival-name-generator-ideas https://webdomaingenerator.com https://www.webdomaingenerator.com/page/youtube-name-generator https://www.webdomaingenerator.com/page/blog-name-generator https://webdomaingenerator.com/page/podcast-name-generator
Your answer
 
 
             Follow this Question
Related Questions
problem whit Instantiate Prefabs position. 0 Answers
How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer
Why can't I instantiate an object that is +5 in the x and z axis? 1 Answer
How to instantiate in self position. 1 Answer
Setting parent of instantiated object fails (Error: setting parent of prefab is disabled...) 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                