Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NetworkIdentity.netId

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Unique identifier for this particular object instance, used for tracking objects between networked clients and the server.

This is a unique identifier for this particular GameObject instance. Use it to track GameObjects between networked clients and the server.

no example available in JavaScript
//For this example to work, attach a NetworkIdentity component to your GameObject.
//Then, create a new empty GameObject and drag it under your NetworkIdentity GameObject in the Hierarchy. This makes it the child of the GameObject. //Next, attach a TextMesh component to the child GameObject. You can then place this TextMesh GameObject to be above your GameObject in the Scene.
//Attach this script to the parent GameObject, and it changes the text of the TextMesh to the identity of your GameObject.

using UnityEngine; using UnityEngine.Networking;

public class NetworkIdentityNetID : MonoBehaviour { NetworkIdentity m_Identity; //This is a TextMesh component that you attach to the child of the NetworkIdentity GameObject TextMesh m_TextMesh;

void Start() { //Fetch the NetworkIdentity component of the GameObject m_Identity = GetComponent<NetworkIdentity>(); //Enter the child of your GameObject (the GameObject with the TextMesh you attach) //Fetch the TextMesh component of it m_TextMesh = GetComponentInChildren(typeof(TextMesh)) as TextMesh; //Change the Text of the TextMesh to show the netId m_TextMesh.text = "ID : " + m_Identity.netId; } }

Did you find this page useful? Please give it a rating: