Warning when setting focus to a TextField

I’ve got a multiline TextField visual element in my ui. When calling Focus() for that visual element I get the following warning:

Can't Generate Mesh, No Font Asset has been assigned.

I don’t have anything special in text settings


Any advise on what the warning means and how I could avoid getting it?

In the UI Builder theme selection dropdown you probably don’t have the theme you are using at runtime. Could it be possible that you created your own theme that doesn’t inherit from the default runtime theme?

Thanks for a suggestion. I tried recreating my theme file with “Create>UI Toolkit>Default Runtime Theme File” and setting it into my PanelSettings, but it had no effect - the warning is still there.
But I have made a different experiment - if I set focus one frame later everything works as expected without warning.
So what I’m doing is:

  • in Update() set UIDocument’s enabled to true
  • query root visual element for my TextField
  • call Focus() on text field visual element - receive the warning
    If I postpone calling Focus() for one frame - voila! there is no warning.
    So can it be that calling Focus() right upon activation is somehow “wrong”?

Thanks a lot, this extra information help tremendously.

This is something we will have to improve on our side: Seems like you are calling focus() while the element are on a panel, but before the styles have been resolved (as the only get calculated at the end of the update) Whatever we do there should not require the final style value and we should delay the usage of the style anyway if they are needed.

Can you fill a bug with that? It will allow you to track the resolution and it seems like you have already a project that reproduce the problem.

You can probably call focus() in the LateUpdate in the meantime, as the styles would be applied to the element at that moment and you wouldn’t have a frame of delay.

1 Like

I have filed a bug with a minimal repro project, only have incoming incident number so far: IN-86060

Bug tracker link : [Unity Issue Tracker - “Can't Generate Mesh, No Font Asset has been assigned” warning is thrown when setting Focus() to a visual element]

I have, and it doesn’t help if done in the same frame, i.e. still produces the warning. But next update, as I said, works without warnings.

For anyone interested I can confirm that this has been fixed in Unity 6000.0.26f1