Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by GarrickWinter · Jun 28, 2020 at 07:10 PM · texttexture2dstringdebugfont

Printing a string of text to a Texture2D

I feel like I've scoured the internet on this, but I haven't found anything useful.


I have some strings in my code that I want to add to a Texture2D that's used entirely for debug purposes. The Texture2D is printed to several (dozens or more) files on disk. It's never displayed on-screen. I have no cameras, no objects, no GUI, no renderers in this entire area of my code at all; I'm just building some underlying data processing and debugging systems, and I want intermediate snapshots of certain information throughout the process.


Most of the information is non-textual, but I want to add a bit of text under the main image to help make sense of the debug information. Specifically, I want to create a color-coded legend, so that I can basically stick a series of squares of a given colour along side debug information describing what elements the colors represent. Right now, though, I can't figure out how to take a string of text and print that to the Texture2D I'm exporting as a PNG.


Every answer I find starts with telling the person asking to set up a camera and objects in a scene and a GUI, and that feels like massive, high-maintenance overhead for this situation. Again, I don't have any of those things active during the entire time this stuff is running, and I don't want them. This is essentially a bunch of pre-processing. How would I just take the text and a font I want to print it in, and get a 2D texture straight from that that I can directly add to my Texture2D?


Any information on this would be greatly appreciated!


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GarrickWinter · Jul 02, 2020 at 09:10 PM

So I've still yet to find somethind truly satisfactory, but so far this is the least cumbersome or irritating solution I've found: https://answers.unity.com/questions/513338/text-to-textureimage.html


It's still not ideal because

  1. Displaying the text on the screen means I can't produce a transparent image with ONLY the text, which I could then happily stamp onto other images; I need a solid background colour to hide whatever's happening in the background.

  2. Displaying the text on the screen, even for just one frame, obviously means the player might see it, so this isn't great for any situation where I'd want to do this during the game.

  3. It doesn't provide me an immediate response, because I need to display the text with OnGUI and then wait till the end of the frame. This means whatever is trying to convert text to image needs to make a request and then stop and wait for the request to be fulfilled, which is a bit more code overhead than I'd like.

  4. Doing multiple prints of text to textures requires either doing them one after the other, which would take several frames, which increases the risk of #2 happening; or batching them. Batching them requires spacing the requested text across the screen, which is more code to write, and increases the risk of #2 being severe when it does happen.

  5. Because this relies on screenspace, there's an inherent limit to how much I can convert at once. This shouldn't be a problem unless doing a lot of text at once, but it could certainly become an issue if you're trying to print whole paragraphs.


So if anyone has a better solution, please let me know.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

215 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to properly display debug messages on UI 0 Answers

Text to Texture2d / png 0 Answers

Text UI looks different (same font) ?? 1 Answer

Using Japanese in my game 1 Answer

How to detect the length of an input field [C# noob] 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges