Godot-docs: Clarify autoloading scripts on the documentation.

Created on 9 Sep 2019  路  5Comments  路  Source: godotengine/godot-docs

The documentation on Autoload states:

You can use AutoLoad to load a scene or a script that inherits from Node. Note: when autoloading a script, a Node will be created and the script will be attached to it. This node will be added to the root viewport before any other scenes are loaded.

From this paragraph I (wrongly) understood that you can Autoload any script, and that if that script does not inherit from Node then a Node will be created anyway and added to the root.

I created a script that inherited from Object and was confused why it wasn't Autoloading. That was 100% my fault for misunderstanding the documentation, of course, but I would not have lost so much time if it had stated something like the following:

You can use AutoLoad to load a scene or a script. Since the object instantiated from the script will be added to the viewport your script must inherit from Node.

Additionally: perhaps a warning that you are trying to autoload something that is not a Scene or a Node-inheriting script could be very useful.

enhancement

Most helpful comment

You can use AutoLoad to load a scene or a script that inherits from Node.

It already says that if your scene or script inherits from Node, then autoload will work. It should be inferred that if your scene or script does not inherit from Node, then be prepared to bang your head against a wall trying to debug why autoload does not work.

All 5 comments

Uh, I fail to see how it's a complex proposal that necessitates discussing here as opposed to a simple issue on the main godot repo or the godot documentation repo?

Uh, I fail to see how it's a complex proposal that necessitates discussing here as opposed to a simple issue on the main godot repo or the godot documentation repo?

The main godot repo is not accepting any enhancement or feature requests, I assumed that extended to documentation modifications. I wasn't aware of the documentation repo, and you're right that it would have made more sense to post it there, my bad.

You can use AutoLoad to load a scene or a script that inherits from Node.

It already says that if your scene or script inherits from Node, then autoload will work. It should be inferred that if your scene or script does not inherit from Node, then be prepared to bang your head against a wall trying to debug why autoload does not work.

Shouldn't the engine itself print an error message when attempting to autoload a script that doesn't extend from Node or any of its descendents?

It does in 3.2:
Screenshot_20200313_115533

Was this page helpful?
0 / 5 - 0 ratings