Godot: "Non-static function 'func name' can only be called from an instance" when AutoLoading a script

Created on 17 Jul 2019  路  2Comments  路  Source: godotengine/godot

Godot version:
Godot 3.1.1.stable.mono.official

OS/device including version:
Windows 10

Issue description:
I created a script called "network.gd", I added a function called "create_server()" in it. Then I added it as a AutoLoaded script and tried to use it in another script. When I tried to run the project it showed me that error - "_Non-static function 'create_server' can only be called from an instance._" when AutoLoading a script"

Steps to reproduce:

  1. Create a script, name it "networking.gd"
  2. add a method "create_server()":
func create_server():
    # Initialize the networking system
    var net = NetworkedMultiplayerENet.new()

    # Try to create the server
    if (net.create_server(server_info.used_port, server_info.max_players) != OK):
        print("Failed to create server")
        return

    # Assign it into the tree
    get_tree().set_network_peer(net)
  1. Add the script to AutoLoad
  2. Try calling network.create_server() from another script

Minimal reproduction project:
SimpleNetworkingPractice.zip

archived

Most helpful comment

This is because you used class_name with the same name as Autoload. It's the same as #28187

All 2 comments

This is because you used class_name with the same name as Autoload. It's the same as #28187

Yes, that was the case. Thanks :)

Was this page helpful?
0 / 5 - 0 ratings