- Home /
Question by
JimNotaro · May 04, 2017 at 10:47 AM ·
networkingclient-server
Server unable to spawn prefab
I have a client and server running for a unity game I'm making. However when I try to instantiate a spell on the client I get this error
Found no behaviour for incoming [Command:InvokeCmdCmdCastSpell] on Player(Clone)
(UnityEngine.GameObject), the server and client should have the same NetworkBehaviour instances
[netId=2].
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
This is the code I'm using to spawn the spell
void checkCast(){
if ((Input.GetMouseButtonDown (0)) && nextcast < Time.time) {
CmdCastSpell (playerStats.primarySpell);
stats.primaryCasts += 1;
}
if ((Input.GetMouseButtonDown (1)) && nextcast < Time.time) {
CmdCastSpell (playerStats.secondarySpell);
stats.secondaryCasts += 1;
}
}
[Command]
void CmdCastSpell(GameObject spell){
try{
SpellControl sc = spell.GetComponent<SpellControl> ();
if (sc.cost*playerStats.costMultiplier <= playerStats.mana) {
playerStats.mana -= sc.cost * playerStats.costMultiplier;
nextcast += sc.reloadTime;
GameObject s = Instantiate (spell, castPoint.transform.position + castPoint.transform.forward * 2, castPoint.transform.rotation);
NetworkServer.Spawn (s);
}
}catch{
SpellControlSingle sc = spell.GetComponent<SpellControlSingle> ();
if (sc.cost*playerStats.costMultiplier <= playerStats.mana) {
playerStats.mana -= sc.cost * playerStats.costMultiplier;
nextcast += sc.reloadTime;
GameObject s = Instantiate (spell, castPoint.transform.position + castPoint.transform.forward * 2, castPoint.transform.rotation);
NetworkServer.Spawn (s);
}
}
}
The try catch is just a way to keep single player in the game at the moment
Also both primarySpell and secondarySpell are register with the Network Manager as spawnable prefabs
Comment