This problem is a bit convoluted and has taken me hours to even identify what is going on. I’m hoping someone here will be able to help me understand why so I can make it stop.
I have a health bar that shifts to the left behind a mask as an enemy takes damage. This is done with a simple position command. Here’s the weird behavior - if I close and reopen Unity then run the program, the bar disappears completely and has receives a position of -54.33333, -298.35. But, if I move the script to another game object and then back to the original one (or even just drag it back onto its own gameobject in the hierarchy), it receives the correct position of 0,0.
No prefabs involved. Since it’s part of the UI, I just have it in the scene. I literally move the script in the inspector to the same parent object in the hierarchy and it fixes the problem.
Update with solution in case anyone else runs into this madness:
The issue was being caused by a timing issue. The function was being called before the Start where values were properly initialized. I moved where the first call happens and no more issues. Still not sure why moving the script onto the gameobject would change this, unless it messed with the behind-the-scenes hierarchy of when GameObjects are initialized into the scene.