Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to lock a TMP Canvas to game view?

Discussion in 'Scripting' started by zakaran, Sep 28, 2022.

  1. zakaran

    zakaran

    Joined:
    Aug 12, 2019
    Posts:
    5
    Been trying to figure this out for hours. ScreenWorldToPoint will just toss it miles away. Keep coming across changing the rendering mode of the canvas, but TMP disables the option to do that.

    All I'm trying to do is lock a TMP text to the top right of the game view (with padding; not all the way into the corner), where it stays at that position even when changing cameras.
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,646
    TMP doesn't disable the option, perhaps you're doing something else wrong?

    You could always just try to make a new Canvas in Screen Space and put your text in that.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    That is a very interesting API name. Do you perhaps have a link to the documentation for it?
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,893
    There's nothing special about TextMeshPro in this regard. It behaves like any other UI element. Simply set the anchor preset to the top right and offset it slightly. You shouldn't need to write any code at all. Also make sure you're using a Screen Space - Overlay canvas.

    One thing to double check is make sure you're using TextMeshPro (UI) which is a UI element, and not TextMeshPro which is a game world thing.