Unity and Visual Studio debugger disagreeing on transform values

Hi all - I’m trying to debug what seems like a very simple issue but I’m completely baffled.

Background: I have a very simple 2D game that has a vertically infinite scrolling background. I’m just using two copies of the same seamless background image stacked on top of each other. As soon as one scrolls out of the camera’s view, it re-positions itself on top of the currently visible one, and around and around they go. Seemed simple enough to me, but maybe there’s a logical issue there?

In order to position the background tile correctly, I simply push it up the y axis twice its unit height (i.e. if the tile had a unit height of 12, I’d add 24 to its transform’s y). That should place it directly on top of the other copy, assuming they were lined up top to bottom correctly at the start. This is the exact (very simple) script I’m using here.

However, in-game, the background sprite’s position is only being increased by a little more than half that, making the two tiles overlap inappropriately. I figured I’d done the math wrong on the re-positioning, but I can’t figure out what. The values Unity is showing me simply do not reflect the manipulations I’m making in the scripts - I’m adding a number to the y value of a sprite’s transform, but that addition is being completely fudged in game. I’m further confused by what the debugger is showing me vs. what the Unity editor is showing me with regards to the position of the sprites, illustrated here.

How can one sprite, in the same frame, have a completely different transform in-engine vs. in the script runtime? What have I done fundamentally wrong here?

Without seeing the whole scene is hard to tell, but my guess is that your “BG1” GameObject is actually child of another object on the scene.
In that case, the inspector is showing you the transform.localPosition values (relative to parent), where the code is displaying the transform.position (relative to the world).

If your BG1 object is really child of anything, try to manipulate the transform.localPosition instead.