How do I change fonts while my game is running?

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

I’m new to Godot so I apologize if I don’t word things correctly or if my question has a simple answer. I’m trying to get the game to change fonts while its running, but whenever I try and change it using add_font_override the text disappears. This is roughly what I’m doing:

onready var menu = $Menu
var font_array = []
var target = 0

func _ready():
  dir_contents("res://fonts/")

func dir_contents(path):
  var dir = Directory.new()
  if dir.open(path) == OK:
    dir.list_dir_begin()
    var file_name = dir.get_next()
    while file_name != "":
      if dir.current_is_dir():
        pass
      else:
        var temp_font = "res://fonts/" + file_name
        var dynamic_font = DynamicFont.new()
        dynamic_font.size = 16
        dynamic_font.font_data = load(temp_font)
        font_array.append(dynamic_font)

func _on_Button_input(event):
  target += 1
  if target > len(font_array) - 1:
    target = 0
  menu.add_font_override("normal_font", font_array[target])

All the fonts I’m using are in ‘res://fonts/’. I currently only have 3 fonts, two being .ttf and one being .TTF, though the same problem happens even if I remove the .TTF file.