- Home /
Prefab not spawning on client correctly
I'm making a multiplayer fps, and I'm trying to add a gun to the player as soon as they spawn. On the host it works great, but on the client it says 'ArgumentException: The thing you want to instantiate is null'. I'm running one instance on the editor and one in a build, if that helps. The weapons all have NetworkIdentities. Weapon spawning code:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class WeaponryHandler : NetworkBehaviour {
//Public vars
public GameObject Gimbal;
public GameObject StartingWeapon;
//Private vars
private GameObject CurrentWeapon;
public override void OnStartLocalPlayer ()
{
base.OnStartLocalPlayer ();
Debug.Log (isLocalPlayer);
Cmd_EquipWeapon (StartingWeapon);
}
[Command]
void Cmd_EquipWeapon(GameObject Weapon){//Try read Prefab from file
Debug.Log ("rekskoped");
GameObject wep = (GameObject)Instantiate (Weapon, Vector3.zero, Quaternion.identity);
wep.transform.parent = Gimbal.transform;
NetworkServer.Spawn (wep);
Rpc_SyncGun (wep);
}
[ClientRpc]
void Rpc_SyncGun(GameObject wep){
wep.transform.parent = Gimbal.transform;
wep.transform.localPosition = Vector3.zero;
wep.transform.localRotation = Quaternion.identity;
}
}
I think your StartingWeapon gameobject is either not populated in the inspector, or getting knocked out at runtime. Is it still there in the inspector when this fails?
Yeah. I checked if it was being removed from the inspector for some reason, but it's still there. $$anonymous$$aybe a problem with how it's being instantiated?
Answer by JackTheKreator · May 20, 2016 at 04:55 PM
FIXED! Only basic types can be sent through commands!
Your answer
![](https://koobas.hobune.stream/wayback/20220612080612im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiplayer - creating server/client non-authorative with the FPS prefab 1 Answer
ArgumentException: The prefab you want to instantiate is null. 1 Answer
Calling the Experts! Problems with Networking: Client/Server Architecture 1 Answer
How do I scale my prefab over the network? 0 Answers
Cant move FPS controller 1 Answer