- Home /
Question by
JackTheKreator · May 23, 2016 at 11:16 PM ·
networkingprefabspawnsync
UNet Parent System
In my FPS, I have a command that spawns a prefab and sets it's parent. It works fine on the host but on the client it's not parented. I tried calling an RPC when it is spawned, but that wont work, because this game is going to be one of those games where anyone can enter/leave a match at any time. So how can I set an object's parent across the server, and for all clients? I use this code to spawn the prefabs-
[Command]
void Cmd_EquipWeapon(NetworkHash128 id){
GameObject go = null;
ClientScene.prefabs.TryGetValue (id, out go);
if(go != null){
GameObject wep = (GameObject)Instantiate (go, Vector3.zero, Quaternion.identity);
NetworkServer.Spawn(wep);
wep.transform.SetParent(Gimbal.transform);
wep.transform.localPosition = Vector3.zero;
wep.transform.localRotation = Quaternion.identity;
}else{
Debug.LogWarning ("Couldn't equip weapon: Asset ID invalid! AssetID = " + id.ToString ());
}
}
Comment