+1 vote

I am making a multiplayer game with a server and two clients. When I run them they connect to each other but rpc doesn't work.
server code:

extends Node2D

func _ready():
    var peer = NetworkedMultiplayerENet.new()
    peer.create_server(8765, 2)
    get_tree().network_peer = peer

    get_tree().connect("network_peer_connected", self, "_player_connected")

var players=[]

func start():
    print("game started")

func start_game():
    rpc("start")#this is the thing that doesn't work

func _player_connected(id):
    if len(players)==2:

client code:

extends Node2D

func _ready():
    var peer = NetworkedMultiplayerENet.new()
    peer.create_client("the ip of the server was here", 8765)
    get_tree().network_peer = peer

    get_tree().connect("connected_to_server", self, "_connected_ok")

func _connected_ok():
    #this function does get called, so I know that it has connected to the server.
    $CenterContainer/Label.text="waiting for other player"

remote func start():
    #This function should be called by the server when the game starts, but it isn't. 

the client's "start" function does not run when the server calls rpc("start") even though the server and client are connected.

I also get these errors on the client even thought the node path on the client and server are the same:
Invalid packet received. Unabled to find requested cached node.
Invalid packet received. Requested node was not found.

why is the client's start function not being called when the server calls rpc("start") ?

in Engine by (17 points)

Is the node structure of the scene the same on both the server and the client?

the script is attached to /root/connecting on both the server and clients but underneath that they are different

Yeah, in order for rpc to work it must be on a node with the same name / heirachy above it

the node with the script does have the same name and node path on the client and sever

I don't see anything telling it to call start_game()

it does in the last line of the server code,
and I have made sure it is being called by making it print something, so I know that works.

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.