This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

accesing custom font size via GDscript

gaby424gaby424 Posts: 20Member
edited June 2019 in 2D


I'm instantiating in my main scene a button that is in a separate scene.
I can set it`s position easy in my code.

But I can`t do it for the font size. The error I get is : Invalid get index "custom_fonts" (on base: 'button')


  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin
    edited June 2019

    Looking at the documentation for the Button node, I am not sure how the editor is setting the font. Apparently according to the theme properties, you can access the font simply through font, but I think you need to get the theme to do that, which would make the code: theme.font.size = 130.

    Looking at the documentation for Control, there are functions called has_font_override and add_font_override that both look promising, but I have no idea how to use either function and the documentation doesn't say.

    Maybe code like this would work? I haven't tested it, but maybe?

    extends Button
    export (Font) var button_font
    # Other code here!
    func on_b_M_pressed():
        # Other code here!
        button_font.size = 130
        user_memory_items[-1][0].add_font_override("font", button_font)

    But I'm just guessing at how the add_font_override function works.

    I am also curious to know if there is a way to access the custom font field like in the editor, as I thought this was already exposed to GDScript through a property.

  • DrZanuffDrZanuff Posts: 1Member

    I know this is old, but in case somebody need this in the future, here is my solution:

    $Label.get("custom_fonts/font").size  = font_size # Set Font
    $Label.get("custom_fonts/font").size # Get Font
  • HaledireHaledire Posts: 23Member

    Another option is:

    This is a method inherited from Control. This will get the font currently used by the node whether you have an override or not. It is also possible to look to the inherited theme from this using the type parameter.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.