This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

im trying to get usernames working for my multiplayer games (in the sense of a hovering label above each player) for about... a full day worth of trial and error(?) now and still no luck, i usually end up with a result where every player node has the same name as what the client has


i came up with a solution which i thought for sure would work, that being sending an rset on ready if the node is the network master, and if not, call an rpc for a function that makes the master node call rset

using Godot;
using System;

public class Username : Label {
    /* setup */
    private Client UserClient;

    public override void _Ready() {
        RsetConfig("text", MultiplayerAPI.RPCMode.Puppet);

        UserClient = GetNode("/root/Server");
        Text = UserClient.Username;

        if (IsNetworkMaster()) {
            Rset("text", UserClient.Username);
            GD.Print("is network master");
        } else {
            Rpc(nameof(_RsetForNewPlayer));
            GD.Print("is not network master");
        }
    }

    /////////////////////////////////////////////////////////////////////////////////////
    /* rpc */

    [Remote] public void _RsetForNewPlayer() {
        if (IsNetworkMaster()) {
            Rset("text", UserClient.Username);
            GD.Print("received");
        }
    }
}

but of course, it just had to not work. i noticed that both "is network master" and "is not network master" print fine, but "received" is never printed

so the only conclusion i can make of this is that rpc is broken in some way, or i somehow fucked it up, im not sure. all i know is its never received and thats been causing me a migraine for the past few days. any ideas why or how to fix it?

Godot version 3.5.1
in Engine by (19 points)

1 Answer

0 votes
Best answer

i found the fix. add a sleep before calling rpc/rset in ready, to make sure that the node youre trying to rpc to actually already exists on the other client

on c#, use System.Threading.Tasks and run something like this in an async function to have a sleep function await Task.Delay(TimeSpan.FromMilliseconds(50));

by (19 points)
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.