#Null Reference String ONLY in WebGL

28 messages · Page 1 of 1 (latest)

tame oxide
royal scarab
#

Is the string null on WebGL in SetName?

tame oxide
royal scarab
#

You've logged it to confirm?

tame oxide
#

If I remove [ServerRpc] then it goes through

tame oxide
#

Clients can set their name and its happy days, floating text above the player e.t.c 🙂

#

If [ServerRpc] is removed, then the string goes through, however, the name doesn't get updated.

royal scarab
tame oxide
royal scarab
#

That doesn't add up

tame oxide
#

Yeah wait.

#

They NEED the [ServerRPC] ServerSetName() to set their name and have it then viewable by themselves and other clients

#

But the string goes through to SetName method

#

Holy shit im so confused.

#

Ok SO.

#
  1. Everything works fine on Windows builds, clients and server.
  2. ServerSetName encounters a bug in WebGL where newName string is null.
#
  1. Clients in WebGL can still set their own name regardless of this bug
royal scarab
#

I think it's time to simplify. Try calling a ServerRpc with a string in OnStartClient if IsOwner on a NetworkBehaviour script placed on a player object spawned by the PlayerSpawner component

#

that was a mouthful xD

tame oxide
#

Ahhh

#
 private void _input_OnSubmit(string text)
    {

        if (text.Length > MaxCharacterLimit)
        {
            text = text.Substring(0, MaxCharacterLimit);      // Truncate the input text to the maximum character limit
        }

        submittedText = text; // Store the submitted text
        Player.SetName(submittedText);
    }

heres where it all begins.

#

This calls the original SetName

#

Setname calls ServerSetName

tame oxide
tame oxide
#

This script is placed on the client instance object that is spawned by the player spawner.

And it works correctly!

    public override void OnStartClient()
    {
        base.OnStartClient();
        
        scoreboardDisplayer = FindObjectOfType<ScoreboardDisplayer>();

        if (base.IsOwner)
        {
            Instance = this;
            playerName = $"Player [ID:{base.ObjectId}]";
            isAlive = true;
            StringSendServerRpcTest(playerName);
        }
    }


 [ServerRpc]
    public void StringSendServerRpcTest(string playerName)
    {
        Debug.Log("Hello World!");
        Debug.Log(playerName);
    }

Is successful and debug Logs correctly!

tame oxide
#

The final line is null now.

 [ServerRpc]
    public void ServerSetName(string newName)  // client tells server to set name   // and also scoreboard
    {
        //Debug.Log(newName);
        playerName = newName;  
        Debug.Log(newName);


        Debug.Log(controlledShip);
        controlledShip.nameDisplayer.SetName(playerName); // set name for client

        
        scoreboardDisplayer.AddScoreboardEntry(playerName, kills, deaths, ObjectId); // !! NULL HERE ONLY NOW !!!
    }
tame oxide
#

Making progress, just leave this thread for a couple hours