#I have issues with my Unity Online Code
1 messages · Page 1 of 1 (latest)
So I have a system that grabs a local input name
coverts that text information to rename the game object so that the other clients can read that info
Unfortunately it results in (__) nothing so it try to grab the username but inputs nothing
Converts text to string to replace player object name
What's your understanding as to why it's resulting in __?
That there is a conversion error
It's been an issue for so long that's I've avoided it as a whole
I've tried AI's and they all say my code work and should work
AI isn't as intelligent as you might hope 💔
That I am sad to say is true
can you share a snippet for how you're collecting text for the name?
sure
Also when you say the value is "(__)" nothing, do you mean that the value is "" (empty string)? Or is it "__"? Or "(__)"? or sometihng else
The blank is a null refrence exception
oh I see - probably better to write that it's null, then
public void NameConfirm()
{
if (string.IsNullOrWhiteSpace(inputName.text))
{
Debug.Log("No Name Entered");
}
else
{
Canvas0.SetActive(false);
displayName.text = inputName.text;
PLI.PlayerNameText.text = inputName.text;
displayName.gameObject.SetActive(true);
// Update the host name when the client confirms their name
if (IsServer)
{
hostName = inputName.text;
UpdateHostName(hostName);
}
hostName = inputName.text;
// Update the displayName field
GetComponent<TankController>().name = displayName.text;
}
}
This is the function and it is run when a player readys in the game
So is the code going to string.IsNullOrWhiteSpace(inputName.text)?
lemme get the error id
NullReferenceException: Object reference not set to an instance of an object
UnityWebRelay.NameConfirm () (at Assets/Scripts/Lobby Code/UnityWebRelay.cs:144)
UnityEngine.Events.InvokableCall.Invoke () (at <6f7018b8b8c149e68c4a65a05ac289be>:0
Which line is that? I don't have line numbers
144 would be at the part I sent you (GetComponent<TankController>().name = displayName.text;)
So is the null reference at GetComponent<TankController>() or displayName?
I have no clue
NullReferenceException: Object reference not set to an instance of an object
well you definitely need to figure that out to resolve the issue
Given that you access displayName in previous lines, I'm guessing that the game object doesn't actually have a TankController
TankController
You might want to make use of TryGetComponent, https://docs.unity3d.com/ScriptReference/Component.html
it's issue is TankController.OnNetworkSpawn
This is also check so that one the buttons press
public override void OnNetworkSpawn()
{
if (!IsOwner)
{
enabled = false;
}
// Rename the player prefab
if (IsOwner)
{
gameObject.name = GetComponent<UnityWebRelay>().hostName;
}
}
That code is run on the Tanks Side or Player 1 or Host
same issue, it can't get the name of the UI name component attached to UnityWebRelay
I'll use this and read through a bit