#Null Reference String ONLY in WebGL
28 messages · Page 1 of 1 (latest)
Is the string null on WebGL in SetName?
No. Only In ServerSetName
You've logged it to confirm?
If I remove [ServerRpc] then it goes through
Yes definitely confirmed this
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.
Using only the SetName method?
Correct
That doesn't add up
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.
- Everything works fine on Windows builds, clients and server.
- ServerSetName encounters a bug in WebGL where newName string is null.
- Clients in WebGL can still set their own name regardless of this bug
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
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
Ok great idea lets rewind then
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!
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 !!!
}
Making progress, just leave this thread for a couple hours