Design-time data

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By linkdude240

Is there an established way to assign required sample data in design time without actually assigning a “real” value in the inspector?

In Visual Studio, when designing UIs, it is possible to visualize the UI with sample mock data, more information at the below link (TL;DR: they use an XML namespace “d” to provide mock design time data)

I feel like this is something so common in UI design, you just want something as a preview just for when you’re in the editor. Overriding each respective value in _ready feels so sloppy to me (but I can live with it I guess…?)

Is there some better way to populate this so that UIs can be quickly visualized by putting in a placeholder or some other such data?

Example: In the GDQuest Learn Code from Zero with Godot series, when designing the Dialog tree scene, they have the character sprite in the texture rect (good) but to see how the RichTextBox for the dialog is rendering you need to type in text to the text box itself, and there is no way to view the buttons that would, at game time be populated by a dictionary without adding real buttons to the scene. Godot is mature enough I’m sure there is design time content, at least that’s what my gut tells me.

Thanks in advance!

There is no such built-in feature, but here are my ideas regarding it:

  • LineEdit has a placeholder text field, but this might not actually decreate the work you have to do
  • You could make a couple of tool scripts that inherint the types you want to preview, and the tool would update the contents only in the editor
  • Text elements translate their contents by default (so if the text in a label is a key to a translation, it’ll be converted to the translated text). You can use this by having keys in a translation that are the “design-time data”, and their translated text is just an empty string. That way in the editor you see your preview, but in game it’ll be updated to be empty by default and you’ll then populate with whatever you want.

zhyrin | 2023-03-08 10:18

I like your suggestions. It’s a little unfortunate that it’s not something built in, but these are workable solutions. Thanks!

linkdude240 | 2023-03-09 02:33