Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Texture 'Font Texture' is not readable

Discussion in '2D' started by Lewissss, Mar 16, 2015.

  1. Lewissss

    Lewissss

    Joined:
    Dec 7, 2013
    Posts:
    13
    Im trying to pull the texture from a Text Mesh object, to then perform some computer vision on it.

    However, whenever I attempt to get the texture i got the message:

    UnityException: Texture 'Font Texture' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
    TestFontGrab.SaveTextureToFile (UnityEngine.Texture2D texture, System.String fileName) (at Assets/Scripts/MyScripts/TestFontGrab.cs:19)
    TestFontGrab.Start () (at Assets/Scripts/MyScripts/TestFontGrab.cs:14)

    I've read on the internet that if you change the font to Unicode, and then create an Editable Copy and ticking the read/write box it should work. But im still getting the error even after doing this.

    Im using

    texture = (Texture2D)GetComponent<TextMesh>().font.material.mainTexture;

    to try and get the texture.

    Thanks,

    Lewis
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    After creating the editable copy, did you switch everything over to use the new texture?

    --Eric
     
  3. Lewissss

    Lewissss

    Joined:
    Dec 7, 2013
    Posts:
    13
    I did not ...

    Would I just drop the new texture file into the font on the text mesh?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Textures and fonts are two different things. You'd make a material with the font texture and use that along with the correct font.

    --Eric
     
  5. Lewissss

    Lewissss

    Joined:
    Dec 7, 2013
    Posts:
    13
    I don't quite understand how to then use the Texture as a font.. Would you be able to elaborate?
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Did you make a material with the font texture (typically using the GUI/3D text shader) and use that along with the correct font?

    --Eric
     
  7. Lewissss

    Lewissss

    Joined:
    Dec 7, 2013
    Posts:
    13
    At the moment Im using a Text Mesh (As the game is 2D), am I not able to use Text Mesh's?
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's precisely what I'm talking about.

    --Eric
     
  9. Lewissss

    Lewissss

    Joined:
    Dec 7, 2013
    Posts:
    13
    Ahh, that does now grab the font texture. However, it grabs the entire font sheet, not just the individual letter?
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Correct, all letters are combined into a single texture.

    --Eric
     
  11. Lewissss

    Lewissss

    Joined:
    Dec 7, 2013
    Posts:
    13
    I can see that, but it is possible to retrieve a single letters texture from the combined texture?
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's what the character rects in the font are for.

    --Eric
     
  13. Lewissss

    Lewissss

    Joined:
    Dec 7, 2013
    Posts:
    13
    How do you actually access the character Rects though? I've found how to access character Info, but no Rects.