Characters missing in chinese and japanese fonts

Hello, I’m still not sure I understand what you mean by reference to the TTF file. How is the notoUnivFont assigned in Unity / how is the notoUnivFont.url file generated?

I’m not sure I can follow –

  1. Out of curiosity, why do you want to switch fonts? Why not use Noto for both cases here for consistency?
  2. Needle never copies TTF fonts to “assets”. Could you share the code that you’re using that does this?

image

@serializable(FileReference)

  notoUnivFont?: FileReference;

Like this

The requirement here is to use Roboto for english as it does not support cjk, i have to switch the font runtime when its not english

This code snippet will indeed literally copy out the TTF asset and do absolutely nothing else. This is NOT a valid font to use for UI, it’s really just “copy that file out”.

Let me check what the right code is

checkAndSwitchFont(currentText: Text) {

    if (currentText && !ComponentDataContainer.instance.isEnglish && ComponentDataContainer.instance.notoUnivFont) {

      currentText.font = ComponentDataContainer.instance.notoUnivFont.url;

      console.log(currentText.font)

    }

  }

This is how i currently switch font in runtime

As said, this code sets a URL (string) on a font (font object) – apples and bananas basically :slight_smile: I’m pretty sure you’re ignoring compiler warnings there!

But good news: I found a solution for you. You can update the font dynamically by using the font from another text object in your scene. This way, you get all the correct setup, the font assets are correctly generated on export, and it “just works” as expected.

We’ll see if we can make this easier in future versions – but for now I hope this unblocks you!

import { GameObject, onStart, Text } from "@needle-tools/engine";

onStart(() => {
    // Just for demonstration purposes, we find all text objects in the scene
    //  and change the font of one of them to match the font of another text object.
    const texts = GameObject.findObjectsOfType(Text);

    // The text object that has the font you want
    const t0 = texts[0];
    // The text object you want to update the font on
    const t1 = texts[1];
    
    // Change the font
    t1.font = t0.font;
    updateFont(t1);
});

/** Helper function to update the font of a text object */
const updateFont = (text: Text) => {
    if (!text) return;
    const uiObject = text["uiObject"];
    if (uiObject) {
        uiObject.set(text["getTextOpts"]());
    }
};

@Ashokkumar_KR I think we can improve this in Needle Engine 4.16 or Needle Engine 5 next week if it helps you. Let me know if that helps. Until then please try Felix solution above.

Hi, This works fine as expected. Thanks a lot

Hi wanted to try out 5.0.0 but got the following error
[Package Manager Window] Error adding package: com.needle.engine-exporter@5.0.0.
Unable to add package [com.needle.engine-exporter@5.0.0]:
Package com.needle.engine-exporter@5.0.0 has invalid dependencies or related test packages:
org.khronos.unitygltf (dependency): Package [org.khronos.unitygltf@2.19.2] cannot be found

Hello @Ashokkumar_KR could you try again? Sorry about that.