Search Unity

Question Converting Screen Space - Overlay to Screen Space - Camera

Discussion in 'Getting Started' started by Tenesty, May 5, 2022.

  1. Tenesty

    Tenesty

    Joined:
    Mar 9, 2020
    Posts:
    1
    Hello,
    I am having an issue with a UI element healthbar. I started making my UI under the screen space - overlay canvas render mode and everything was working fine but I've since changed to Screen Space - Camera as I find it better fits my game.

    After making this change my UI element under my canvas is now being offset to a strange position:
    upload_2022-5-5_14-32-5.png
    The green health bar above is supposed to be right bellow my character as well as the red enemy you see on the screenshot. It works as intended its just not in the right position. Seems like its using my character as a 0,0 position and has a weird offset.

    upload_2022-5-5_14-33-22.png
    This is the function that updates the position. It seems to be an issue with the 0,0 position of WorldToScreenPoint being the center of the screen. However I've tried many things and looked many places and cannot find a way to make the conversion. That function works perfectly if I switch back to Screen Space - Overlay.

    upload_2022-5-5_14-37-57.png
    My Unity Editor window with my canvas settings

    I am trying to remove the offset from the position of the Healthbar on my Canvas. Any help is appreciated thank you.
     
    VionHD and Dark571 like this.