- Home /
Transform.localPosition In Inspector Vs. Code
I am trying to change the Y value of localPosition for a particular game object. I want the Y value to be -.003.
When I set the Y value manually in the Inspector, the mesh rendered by the game object moves slightly (as I expect it to), just graphically clearing an object I am maneuvering it around. (Maneuvering is graphical only; I am not using any Physics or RigidBodies in this project besides the occasional raycast.)
However, when I set the Y value in code, the Inspector shows the new value in the local position (as I expect it to), but the game object does not move slightly and fails to clear the given obstacle.
Here's the relevant line of code:
megaHose1.transform.localPosition = new Vector3(megaHose1.transform.localPosition.x, -.003f, megaHose1.transform.localPosition.z);
The mesh rendered by the game object is handled by a third-party plugin. It's possible there is a bug in that plugin that moves the created hose when the Inspector changes values but not when values are changed via code. (Unfortunately, the plugin author has not responded to multiple unrelated emails requesting support, so I have little confidence in hearing from him.)
At any rate, I'm trying to see if there is anything else that could be causing this behavior before I write it off as a bug in the plugin's code that must be routed around somehow.
One last item...
If I programmatically set the Y value as -.003, I must manually change the value to -.006 in order to get the same effect I would expect if I had no code line at all. Similarly, if I programmatically set the value to -.004, I have to manually change the value to -.007 before I notice the clearance effect.
Any and all help is appreciated!
Your answer
![](https://koobas.hobune.stream/wayback/20220613003249im_/https://answers.unity.com/themes/thub/images/avi.jpg)