• Godot HelpProgramming
  • Attempt to call function ‘queue_free’ in base ‘previously freed instance’ on a null base

My game has been working fine, until I upgraded from v3.2.3 to v3.4.2

Now I get the following error: "Attempt to call function ‘queue_free’ in base ‘previously freed instance’ on a null base"

Here is my code:

func load_menu(menu_name, menu_settings = {}):
	
	if current_menu:
		current_menu.queue_free()

Try using if is_instance_valid(current_menu) instead of if current_menu. The way object validity checks works has changed in Godot 3.4 and later.

You can also set the reference to null after deletion. This is a good practice.

current_menu.queue_free()
current_menu = null

Maybe. But that wouldn't help when there may be copies of the reference. I think that using is_instance_valid() is a better practice.

Well setting to null would work on a per script basis, and solve the problem in this instance for the OP. But yes, if you have multiple scripts referencing the same value or even different variables in the same script, this wouldn't help.

9 months later