Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextLayout.SetEntityTextRendererString with dynamic strings (FixedString)

Discussion in 'Project Tiny' started by collinmmckinney, Feb 9, 2021.

  1. collinmmckinney

    collinmmckinney

    Joined:
    Jun 25, 2018
    Posts:
    6
    Hi, I'm using the new Tiny.UI features, and I have run into one issue. Is there a way to set the value of a text renderer's text to be a FixedString4096? I have user input for entering a name, and I'd like to be able to use that value (which I have saved as a FixedString4096 on a data component) in the UI. When I try to use that FixedString4096 with SetEntityTextRendererString I of course get "cannot convert from FixedString4096 to string."
    My issue here might be a misunderstanding of how FixedStrings work, or maybe my approach is wrong.

    I would love some help on a work around for this issue as it is pretty essential to my game that I can display names as entered by the user.
     
  2. LeeThomason

    LeeThomason

    Unity Technologies

    Joined:
    Jan 9, 2019
    Posts:
    2
    Collin, that's an oversight in the API, regrettably. I'll get that fixed - in the meantime, you can call FixedString.ToString().
     
  3. v_vuk

    v_vuk

    Unity Technologies

    Joined:
    Jul 11, 2017
    Posts:
    36
    Yep, you're doing all the right things -- we're just missing some API paths. Using FixedString will also let you avoid creating garbage collected memory, so that when we do have a pure FixedString path in the future it will be able to be Burst compiled as well.

    One thing to note though.. using a FixedString4096 means that you're using 4k bytes for every name, regardless of its length. That seems too long for names in a game. Maybe consider FixedString128 or FixedString512?
     
  4. collinmmckinney

    collinmmckinney

    Joined:
    Jun 25, 2018
    Posts:
    6
    Thank you both! I didn't realize that FixedString.ToString() worked -- that's exactly what I was looking for. And I will definitely revisit the size of the strings, that's a great point. Thanks!