- Home /
(UNITY MIRROR) Server/Client functions not being called from instantiated objects
So I'm new to Mirror so bare with me. I'm currently working on a multiplayer project where players control wizards, casting spells at each other. However, I seem to have a problem with objects "spells" the wizard player character instantiates, with them not being able to call any Command or Rpc functions. Maybe my understanding is a little off but here's the main rundown.
The wizard_player script calls this command function to spawn the currently selected spell.
CmdSpawnSpell(selectedElements[spellToCast].castType, index); ////THIS WORKS FINE
}
[Command]
private void CmdSpawnSpell(SpellIndex.CastType t, int index)
{
RpcSpawnSpell(t, index);
}
[ClientRpc]
private void RpcSpawnSpell(SpellIndex.CastType t, int index)
{
SpawnSpell(t, index, true);
}
private void SpawnSpell(SpellIndex.CastType t, int index, bool isParented)
{
GameObject newSpell;
switch (t)
{
case SpellIndex.CastType.Spray:
newSpell = Instantiate(SpellIndex.SI.spray[index], castPoint.position, castPoint.rotation);
break;
case SpellIndex.CastType.Beam:
newSpell = Instantiate(SpellIndex.SI.beam[index], castPoint.position, castPoint.rotation);
break;
case SpellIndex.CastType.Projectile:
newSpell = Instantiate(SpellIndex.SI.projectile[index], castPoint.position, castPoint.rotation);
break;
case SpellIndex.CastType.Shield:
newSpell = Instantiate(SpellIndex.SI.shield[index], castPoint.position, castPoint.rotation);
break;
default:
return;
}
if (isParented)
{
newSpell.transform.SetParent(castPoint);
currentSpell = newSpell.GetComponent<Spell>();
currentSpell.NormalCast();
}
}
So far all is well, this successfully spawns the spell on the server and all clients. But then for some reason the Command/Rpc functions on the newly instantiated object never get called/listened too.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class Spell : NetworkBehaviour
{
public Wizard_SpellManager.Element.Type elementType;
public float castTime = 3f;
public float castingMovePenaltyPercentage = 0f;
protected bool casting = false;
public float damage = 10f;
public virtual void NormalCast()
{
casting = true;
RpcCast(); //////////DON'T WORK????
CmdCast(); //////////DON'T WORK????
}
[ClientRpc]
private void RpcCast()
{
Debug.Log("HI CLIENT");
}
[Command]
private void CmdCast()
{
Debug.Log("HI SERVER");
}
They all have networkidentity and networktransform. Not only that, but if I replace the playerprefab in the network manager with the spell object, the above code starts working.
Is there a step that I've missed? Do I need to somehow register the newly created object to the network manager so that it can call the server and client commands?
Your answer

Follow this Question
Related Questions
[Mirror Networking] NullReferenceException on player when trying to start server a second time 1 Answer
Mirror: Spawn dynamically created objects (not prefabs) 0 Answers
Stop accepting new player connections in Unity Mirror Networking 1 Answer
Reconnecting a player in an online game... 0 Answers
Can't get Unity Mirror Networking example games to connect between my pc and android 4 Answers