Search Unity

CreateDynamicFontFromOSFont to an asset font in Unity

Discussion in 'Scripting' started by retrophil, Jul 12, 2019.

  1. retrophil

    retrophil

    Joined:
    Mar 16, 2013
    Posts:
    46
    ...is there a way where I can grab an OS font and copy/create it as apart of my Unity project?

    I have tried using Font.CreateDynamicFontFromOSFont and putting it into AssetDatabase.CreateAsset. But all it gives me is a 1kb file.

    This project is going to build in WebGL and WebGL needs the font file within the project.

    I don't want to copy my system font I have manually as the font will differ per user, per project.

    Sorry if this is a repeat problem, I couldn't find anything else like it.
     
  2. calpolican

    calpolican

    Joined:
    Feb 2, 2015
    Posts:
    425
    I think you should find out the font's name first. See if you can actually use it comercially. Otherwise you may search for a similiar one that is free to use. If you know the name and is free to use, you can probably download it from the internet.
     
  3. retrophil

    retrophil

    Joined:
    Mar 16, 2013
    Posts:
    46
    I hear ya. But the user(s) will be transferring their own files into the Unity Editor which contains their own fonts from their OS; which will then be exported out as a WebGL.

    In the editor you can see the fonts working (textmesh), but I need them contained as an asset so they can be built with the project. Manually or looking for a similar font isn't really an option :/
     
  4. calpolican

    calpolican

    Joined:
    Feb 2, 2015
    Posts:
    425
    I'm not sure I follow you.
    In my unity project I can only see the fonts I've added to the assets folder. I have a lot of fonts installed an none is appearing, except Arial, that's probably Unity's default. In my project I have fonts that are not installed in my PC too. I'm almost sure the fonts in my asset folder will get exported and used with the rest of the proyect once I build. Is this a problem related to the use of OpenGL?
     
    Last edited: Jul 13, 2019
  5. retrophil

    retrophil

    Joined:
    Mar 16, 2013
    Posts:
    46
    I can't build to WebGL because I don't have the OS fonts I'm using in my Unity Project Folder. It will error out.
    I have the OS fonts working in my scene because I'm using "CreateDynamicFontFromOSFont ".

    So I'm trying to find a way using/creating the fonts as an asset from my OS into my Unity Project Folder without manually copying the files over from the OS.
     
  6. I don't think this is possible, but I'm not an expert in TMP. I only use it on the originally intended way (pregenerated).

    But @Stephan_B is the expert.

    Stephan is very active in the UI/TextMeshPro forums, usually he answers any questions regarding TMP, so if you choose to post there next time, he can answer or give you advise. (hint :) )
     
  7. retrophil

    retrophil

    Joined:
    Mar 16, 2013
    Posts:
    46
    Ok thanks, I'll hassle him.