Load Font Error

needle-engine.extras.CYXGdbk2.js:194 Error creating font nn {__context: We, name: ‘Text’, gameObject: Mt, guid: ‘2145448023078131911_e32a1b5d512ca944492c1cda04013076_0’, sourceId: ‘./assets/CharacterPrefab.glb’, …} TypeError: Failed to construct ‘URL’: 1 argument required, but only 0 present.
at R
(needle-engine.extras.CYXGdbk2.js:194:2006)
at l (needle-engine.extras.CYXGdbk2.js:179:18397)
at T (needle-engine.extras.CYXGdbk2.js:179:18769)
at UL (needle-engine.extras.CYXGdbk2.js:1433:228)
at needle-engine.extras.CYXGdbk2.js:1428:11308
at Zp (needle-engine.extras.CYXGdbk2.js:827:15767)
at We.internalOnBeforeRender (needle-engine.extras.CYXGdbk2.js:812:2032)
at We.internalStep (needle-engine.extras.CYXGdbk2.js:812:1059)
at We.update (needle-engine.extras.CYXGdbk2.js:812:279)
at needle-engine.extras.CYXGdbk2.js:811:4968

Based on the information provided, it seems that the issue you are encountering is related to a “Load Font Error,” which is triggering a “TypeError: Failed to construct URL” during the attempt to create a font. This error suggests that there might be a problem with how the font resource URLs are being constructed or accessed in your Needle Engine project.

To help you troubleshoot and resolve this issue, let’s gather more information and ask some clarifying questions:

  1. Font Path and File:

    • Can you provide the exact path and filename of the font asset that you are trying to load?
    • Is the font file stored in the correct directory relative to your project structure?
  2. Environment Details:

    • Are you working in a Unity editor or building for WebGL?
    • Have you checked if the font file is correctly included in your build settings?
  3. Project Configuration:

    • Can you show any relevant configuration settings or scripts that might be affecting the font loading process?
    • Are you using any custom font handling or are you relying on the default mechanisms provided by the engine?
  4. Console Warnings:

    • Could you share the full text of the console warning or error message, including any stack traces if available?
    • Are there any specific lines of code that you suspect might be causing the issue?
  5. Font Additional Characters:

    • Have you ensured that only the necessary characters are included in your font atlas to avoid the font atlas being too large?
    • If you are missing certain characters such as Chinese, Japanese, or Korean, did you correctly add the FontAdditionalCharacters component and re-export the font?
  6. Component Setup and Script Usage:

    • Are you using the UI/Legacy/Text component as recommended in the documentation?
    • Have you verified that the text component is properly assigned to a UI element in your scene?

If you provide this information, I can help you further by checking the documentation and relevant sources in Needle Engine to find a solution or workaround for your specific issue.

Sources: Needle Engine Docs (65%), Needle Engine Docs (62%)

1 replies left - Become PRO for more replies.
Reply to this post directly if you need further help (bottom right button)

needle 5.0.1
unity 6000.0.68f1

It seems the error is related to a font creation process in Needle Engine. Here are some steps to help diagnose and potentially resolve the issue:

  1. Check Font Asset Path:

    • Ensure the font asset file path is correctly specified in your project and that the file exists at the expected location.
  2. Verify Project Build Settings:

    • Double-check the build settings to confirm that the font asset is included in the build.
  3. Inspect Script Logic:

    • Review the code where the font is being loaded. Make sure the URL or path to the font file is correctly formatted and correctly referenced.
  4. Update Needle Engine:

    • You are using Needle Engine 5.0.1, which might be an older version. Consider updating to the latest stable version as newer versions might have bug fixes and improvements.
  5. Review Documentation and Examples:

    • Look into the Needle Engine documentation for examples of how to handle font assets. The latest documentation can often provide best practices for setup and usage.
  6. Community Support:

    • Post your specific issues or questions on the Needle Forum for further support and troubleshooting from other users and the development team.

If you could provide the exact path and filename of the font asset, as well as any relevant code snippets, I can offer more tailored advice.

0 replies left - Become PRO for more replies.
Reply to this post directly if you need further help (bottom right button)

version 4.16.7 is ok

Based on the information provided and the error message you shared, it seems the issue is related to the Failed to construct URL error when attempting to create a font. Here’s a potential solution:

  1. Check Font Path: Ensure that the path to the font file is correctly specified. The path should be relative to the asset folder in your Unity project. For example, if your font file is located in the Assets/Fonts folder, the path should be "../Fonts/your-font-file.ttf".

  2. Verify Asset Inclusion: Make sure the font asset is included in the build settings and that it is not accidentally omitted.

  3. Debugging: Add debug logs to verify that the path to the font file is being read correctly and that it contains valid data before the font creation process.

Here is a sample code snippet to help you debug and set up the font correctly:

using UnityEngine;
using TMPro;

void LoadFont()
{
    string fontPath = Application.dataPath + "/StreamingAssets/Fonts/your-font-file.ttf";
    Debug.Log("Font Path: " + fontPath);

    if (!System.IO.File.Exists(fontPath))
    {
        Debug.LogError("Font file not found at the specified path: " + fontPath);
        return;
    }

    TMP_FontAsset fontAsset = Resources.Load<TMP_FontAsset>("Fonts/your-font-file");
    if (fontAsset == null)
    {
        Debug.LogError("Font asset not found in resources.");
        return;
    }

    Debug.Log("Font successfully loaded: " + fontAsset.name);
    // Set the font for your TMP_Text
    GetComponent<TMP_Text>().font = fontAsset;
}

If the issue persists, consider providing more details such as the exact path of the font file and any relevant parts of your Unity setup configuration. If you still cannot resolve the issue, creating a minimal reproducible example and sharing it on the Needle Forum could help get more targeted assistance.

1 replies left - Become PRO for more replies.
Reply to this post directly if you need further help (bottom right button)

Could you provide a small bugreport with this? We havent seen this error in any of our samples.

The error appears when running on a server
but localhost not a bug

I have tried this as well of course - please provide more details about your project / font / and a bugreport so we can investigate. Thank you!

i use this font
Noto Sans Thai - Google Fonts