Search Unity

Getting "There is no NetworkIdentity on this object" but there is one attached.

Discussion in 'Multiplayer' started by Dhee9000, Apr 5, 2017.

  1. Dhee9000

    Dhee9000

    Joined:
    Apr 5, 2017
    Posts:
    1
    I was following the tutorial here:
    and I followed pretty much exactly as is, but I get a no NetworkIdentity on this object, NullReferenceException. The game runs fine but this error shows up in the console. I searched online and there was one thread but he had an issue with the object being a child of another.

    I have a car, with a NetworkIdentity and NetworkTransform attached, registered in the NetworkManager as the Player prefab, with a script that uses isLocalPlayer attached.

    Code (CSharp):
    1. public class SetupLocalPlayer : NetworkBehaviour {
    2.  
    3.     [SyncVar]
    4.     public string pname = "Player Name";
    5.     // Use this for initialization
    6.     void Start () {
    7.         if (isLocalPlayer) {
    8.             this.GetComponent<Driving> ().enabled = true;
    9.             this.GetComponentInChildren<TextMesh> ().color = new Color (0, 221, 255);
    10.         } else {
    11.             this.GetComponentInChildren<TextMesh> ().color = new Color (255, 0, 0);
    12.             Destroy(GetComponentInChildren<Camera>());
    13.             Destroy(GetComponentInChildren<AudioListener>());
    14.         }
    15.     }
    16.  
    17.     void Update () {
    18.         this.GetComponentInChildren<TextMesh> ().text = pname;
    19.     }
    20.  
    21.  
    22.     [Command]
    23.     public void CmdChangeName(string newName){
    24.         pname = newName;
    25.     }
    26. }
    There was initially an old GUI script also, but that caused looots of lag, so I removed it from the sample. I tried another project with multiplayer networking and it threw weird unexplainable issues too. Overall Unity Multiplayer has been a huge pain. I'm relatively a newbie, so if anyone could explain what's going on, I'd really appreciate that!

    I also cannot understand how to access UI element properties from the player object to retrieve player name from a text InputField I have. If someone could explain that too, that'd be great! (I know that's not part of this forum, but it's related to the same script.)