0 votes

im trying to make a simple game wich is a multiplayer version of space invaders (to learn more about networking and whatsoever)
and i ran into this problem:
when i connect to the host the game crashes and an error pops up :
attempt to call function run_server_func on base null instance
here's my code
in the network autoload:

func call_peer(node_path, function, data):
rpc_unreliable("receive_call", node_path, function, data)

remote func receive_call(node_path, function, data):
    get_tree().get_root().get_node(node_path).run_server_func(function, data)

in the player script:

   func _physics_process(delta):
       detect_player_movement()
       network.call_peer("res://entities/Friend.tscn","move", position)

in the friend node(the character the other player is controlling):

func run_server_func(function, data):
if function == "move":
    move(data)

func move(data):
    position = data

thanks for taking a look it means a lot

in Engine by (120 points)

1 Answer

0 votes
Best answer

"res://entities/Friend.tscn" is not a path to a node in the scene tree, it is a path to a "scene resource" file which is something different. For example, if you scene tree is looking like this (you can see it at the topleft of the godot editor during editing and runtime):

Node2D
----MyCharacter
----FriendCharacter

and you want to access FriendCharacter node from root, than node path would be "Node2D/FriendCharacter".

by (96 points)
selected by

thanks for your response i changed it to MainScene/Friend since my scene tree looks like this:

-root
  -network
  -MainScene
      -Friend
      -Player(Node from wich im calling the rpc)

but the same error pops up
any help would be appreciated

Is the scene tree same for both games? If yes, try finding error step by step, start by printing children of root node etc.
for child in gettree().getroot().get_children():
print(child.name)

thanks a lot i tried that and launched the game and now for some reason it works i will never understand this but still thanks so much

This sometimes happens when you use two godot editors, changes to scenes/scripts/nodes etc is not reflected to other editor but it works when you close/reopen the godot, not sure what is the reason. I also encounter this issue (I would say rarely) when developing a multiplayer game.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.