#I have issues with my Unity Online Code

1 messages · Page 1 of 1 (latest)

gleaming wren
#

What's the problem?

spring tide
#

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

gleaming wren
#

What's your understanding as to why it's resulting in __?

spring tide
#

That there is a conversion error

#

It's been an issue for so long that's I've avoided it as a whole

spring tide
gleaming wren
#

AI isn't as intelligent as you might hope 💔

spring tide
#

That I am sad to say is true

gleaming wren
#

can you share a snippet for how you're collecting text for the name?

spring tide
#

sure

gleaming wren
#

Also when you say the value is "(__)" nothing, do you mean that the value is "" (empty string)? Or is it "__"? Or "(__)"? or sometihng else

spring tide
#

The blank is a null refrence exception

gleaming wren
#

oh I see - probably better to write that it's null, then

spring tide
#

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

gleaming wren
#

So is the code going to string.IsNullOrWhiteSpace(inputName.text)?

spring tide
#

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

gleaming wren
#

Which line is that? I don't have line numbers

spring tide
#

144 would be at the part I sent you (GetComponent<TankController>().name = displayName.text;)

gleaming wren
#

So is the null reference at GetComponent<TankController>() or displayName?

spring tide
#

I have no clue

#

NullReferenceException: Object reference not set to an instance of an object

gleaming wren
#

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

spring tide
#

TankController

gleaming wren
spring tide
#

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

spring tide