Search Unity

Question UI elements moving for seemingly no reason

Discussion in 'UGUI & TextMesh Pro' started by DoubleDigitDev, May 2, 2023.

  1. DoubleDigitDev


    Jan 17, 2022
    I made this hacking UI for a mechanic in my game and one of the features is that panel labeled 'stabilize'.
    This panel moves around SOMETIMES in-game and I cannot figure out why. I have been keeping it in place with an animation but I ran into a roadblock which eliminated the option to keep using that workaround. The image below is how it is supposed to appear.

    The image below is how it is when it moves in-game.

    I have no idea why it's doing this. I have checked that it is anchored correctly, and as I said I tried animating it to stay in place. Any suggestions are greatly appreciated!!
  2. Kurt-Dekker


    Mar 16, 2013
    You should not need to animate it to hold it in place. In fact, depending on what property you animate, that might even be making it move!

    UI should just stay where it is, barring something else moving it.

    Common things that move stuff in a UI:

    - layouts (GridLayout Group, HorizontalLayout, VerticalLayout, etc)
    - anchoring / offsetting (or rather, mis-anchoring)
    - animations
    - code

    For code, if you have a
    reference that you intend to use to move something else, and that script happens to be ON a UI item, but you inadvertently use
    instead, then you might get weird things happening.

    Finally, here's some reading on UI Anchoring, Scaling, CanvasScaler, etc:
  3. DoubleDigitDev


    Jan 17, 2022
    Thank you for your reply!! I still have no idea why it is moving. I know it has something to do with the rigidbody connected to it. The mechanic relies on the rigidbody though so I cannot take it off. I Tried messing around with some settings but the only way that seems to be working is by animating it to return it to its x position. I did figure out a way that animating it works without conflicting with the mechanic, so I will keep using that workaround unless I find the root of the problem or discover a more efficient way to solve it.