I use the following code to instantiate the object and rename
Everything is normal host
But when the client performs, warning
Reads
ArgumentException: The thing you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C: /buildslave/unity/build/Runtime/Export/UnityEngineObject.cs: 102)
UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C: /buildslave/unity/build/Runtime/Export/UnityEngineObject.cs: 79)
S4play.Cmdobj (UnityEngine.GameObject me, UnityEngine.GameObject obj, Vector3 post, System.String id, System.String nnmae, Color col) (at Assets / Script / s4 / S4play.cs: 83)
S4play.InvokeCmdCmdobj (UnityEngine.Networking.NetworkBehaviour obj, UnityEngine.Networking.NetworkReader reader)
UnityEngine.Networking.NetworkBehaviour.InvokeCommandDelegate (Int32 cmdHash, UnityEngine.Networking.NetworkReader reader) (at C: /buildslave/unity/build/Extensions/Networking/Runtime/NetworkBehaviour.cs: 299)
UnityEngine.Networking.NetworkBehaviour.InvokeCommand (Int32 cmdHash, UnityEngine.Networking.NetworkReader reader) (at C: /buildslave/unity/build/Extensions/Networking/Runtime/NetworkBehaviour.cs: 77)
UnityEngine.Networking.NetworkIdentity.HandleCommand (Int32 cmdHash, UnityEngine.Networking.NetworkReader reader) (at C: /buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs: 404)
UnityEngine.Networking.NetworkServer.OnCommandMessage (UnityEngine.Networking.NetworkMessage netMsg) (at C: /buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs: 1218)
UnityEngine.Networking.NetworkConnection.HandleMessage (System.Collections.Generic.Dictionary`2 handler, UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) (at C: / buildslave / unity / build / Extensions / Networking / Runtime / NetworkConnection .cs: 301)
UnityEngine.Networking.NetworkServer.InternalUpdate () (at C: /buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs: 652)
UnityEngine.Networking.NetworkServer.Update () (at C: /buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs: 514)
UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at C: /buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs: 706)
My code
public class S4play : NetworkBehaviour {
public GameObject mybody,myind,pbody,pind;
void Start () {
PID = "PLAY"+GetComponent<NetworkIdentity>().netId.ToString();
transform.name = PID;
Vector3 pos = transform.position;
pos += new Vector3(0,20,0);
cobj(gameObject,pbody,pos,PID,"_B");// name = PID+"_B";
cobj(gameObject,pind,pos,PID,"_I");// name = PID+"_I";
}
[Client]
void cobj(GameObject me,GameObject obj,Vector3 post,string id,string nnmae){
Cmdobj(me,obj,post,id,nnmae);
}
[Command]
void Cmdobj(GameObject me,GameObject obj,Vector3 post,string id,string nnmae){
GameObject nobj = (GameObject)Instantiate(obj,post,transform.rotation);
nobj.GetComponent<NBID>().myid = id+nnmae; //Rename
nobj.transform.parent = me.transform; //get parent
NetworkServer.Spawn(nobj);
}