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 /
avatar image
1
Question by BillyMFT · Feb 17, 2015 at 01:14 PM · texttexture2ddynamicscreenshot

add text to a Texture2D while game is running

My game has a feature where it takes a screenshot (Texture2D) and posts it to social media platforms - all pretty standard. I'd like to add some text to the screenshot (score etc) but I'm stuck. Any tips? Thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by BillyMFT · Feb 18, 2015 at 01:28 PM

I ended up doing it with a RenderTexture. Here were the steps I took.

  1. Duplicate the main game camera, call it "ScreenshotCam" and set it to a lower depth (not sure if that was required)

  2. Make a new render texture in the project panel and set it to a decent size

  3. Make the render texture the "target Texture" of the ScreenshotCam

  4. Add some UI text for score and a UI image for the game logo. Put these both on a layer that is only rendered by the ScreenshotCam (ie uncheck the layer in the culling mask dropdown of the main camera)

  5. output the current score to the UI text box as the game is being player

  6. Make the render texture created in step 2 active while taking the screenshot.

Here is the capture function I'm using.

 function CaptureScreen() {
     yield  WaitForEndOfFrame();
     var currentRT = RenderTexture.active;
     RenderTexture.active = scoreRenderTexture;
     var tex = new Texture2D(screenshotScoreCamera.pixelWidth, screenshotScoreCamera.pixelHeight, TextureFormat.RGB24, false);
     // Read screen contents into the texture
     tex.ReadPixels(screenshotScoreCamera.pixelRect, 0, 0);
     tex.Apply();
     
     RenderTexture.active = currentRT;
 return tex;
 }

 

Hope others find this useful.

Comment
Add comment · Show 1 · 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
avatar image nagibatr · Dec 25, 2018 at 02:22 PM 0
Share

Thank you so much!

avatar image
0

Answer by hexagonius · Feb 17, 2015 at 01:23 PM

This should help you, but in general looking into the Texture2D documentation gives you an idea of how to modify a texture (by GetPixels, SetPixels and Apply):

Adding Text-To-Texture at Runtime in Unity3D Without Using Render Texture

Comment
Add comment · Show 1 · 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
avatar image BillyMFT · Feb 17, 2015 at 01:47 PM 0
Share

Thanks. I did see that tutorial in my searches but it seemed a bit dated. Unity iOS can RenderTextures now so I thought there would be a simpler solution. Do you know of any tutorials for adding text to a texture using SetPixels? The unity docs just shows how to make patterns and add colours to pixels. I've read some stuff about using a camera to render some gui text but nothing that actually explains how to do it and add it to a Texture2D.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Display Short message on screen each button press 0 Answers

Wrapping dynamic text around an object. 1 Answer

Render a text on the sprite 1 Answer

Save png with text overlay 3 Answers

Texture.Apply() Crashes at Resolutions under 1920x1080 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