Singletons (Autoload) Documentation incorrect or outdated?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By johannesg
:warning: Old Version Published before Godot 3 was released.

I’ve tried following the Singletons Autoload step by step tutorial both for Godot 2.1.4 and Godot 3 and both have produced the same error which I’ve been unable to figure out.

When the button in scene_a is clicked the game crashes with the following error "Attempt to call function 'instance' in base 'null instance' on a null instance."

The errors point to _deferred_goto_scene function which looks like this.

func _deferred_goto_scene(path):
	current_scene.free()
	var s = ResourceLoader.load(path)
	current_scene = s.instance()
	
	get_tree().get_root().add_child(current_scene)
	get_tree().set_current_scene(current_scene)

More specifically, it seems something odd is happening in ResourceLoader.load(path). the path variable ( res://scene_b.tscn ) gets passed on correctly to the function but ResourceLoader.load(path) still seems to return a [Object:null]. The game therefor crashes on when trying to instance s.

Note that the project I am testing this on is the one downloadable on the mentioned page in the documentation.

Did I miss something or is there something missing from the documentation?

:bust_in_silhouette: Reply From: rolfpancake

//EDIT

The problem are these strings in the latest docs:
"res://scene_a.tscn" and "res://scene_b.tscn"
The downloadable file contains .scn files.

Not sure how you run into this with the stable docs. There the strings are correct…


I tested it with Godot 2.1.4 and Godot 3 beta1 and it works for me.
Here are my project files:

The only problem I came across was this wrong picture in the stable docs:

In 2.1.4 the Path is on the left and the Node Name is on the right side of the window. But no change in behaviour at all.

haha! yes. this is correct. I had both the stable and latest docs open as I was testing this with both Godot 3 and Godot 2. My guess is that I must have alt tabbed to the wrong one when checking the code and then never really noticed the extra t!

Thank you very much for the help. Works now. :slight_smile:

johannesg | 2017-12-11 23:18

No problem. Would you mind creating an issue in the docs repo because of the missing tscn-files in the provided zip file (only latest docs)?

You could link to this thread to make the problem more clear.

rolfpancake | 2017-12-11 23:35

I will look into that, no problem.

johannesg | 2017-12-12 09:20