How do I spawn a Network Object on all other clients apart from the sender

How do I spawn a Network Object on all other clients apart from the sender
I have a fireball spell that I want to Instantiate on local client A, and then send a ServerRpc request to spawn the object on the Network for all other clients but not for client A
The instantiated version is instant so there is no lag in casting or seeing the fireball move for the local client.
But then when the server spawns the network version it also spawns again for Client A so they see 2 fireballs.

I have tried using a ulong array of all clientIDs apart from the LocalClientId and feeding it into ClientRpcParams etc but I can’t seem to get anything to work. The Network Object still spawns for Client A

Here is my base code with the Params taken out as it wasn’t working:

using Unity.Netcode;

private IEnumerator CastingFireballs()
    {
        while (attacking && IsOwner)
        {
            GetPlayerDirection();
            CastFireballLocal();
            CastFireballServerRPC(playerDirection);
            yield return new WaitForSeconds(0.7f);
        }
        yield return null;

    }

    private void CastFireballLocal()
    {
        if (!IsLocalPlayer) return;
        GameObject fireball = Instantiate(spells[0], castPoint.position, transform.rotation);
        fireball.GetComponent<Fireball>().speed = 10f;
        fireball.GetComponent<Fireball>().direction = playerDirection;
    }

[ServerRpc]
    public void CastFireballServerRPC(Vector3 direction)
    {
        if (IsServer)
        {
            CastFireballClientRPC(direction);
        }
    }

    [ClientRpc]
    public void CastFireballClientRPC(Vector3 direction)
    {
        if (!IsServer) return;
        GameObject fireball = Instantiate(spells[0], castPoint.position, transform.rotation);
        fireball.GetComponent<Fireball>().speed = 10f;
        fireball.GetComponent<Fireball>().direction = direction;
        fireball.GetComponent<NetworkObject>().Spawn();

    }

all network objects exist for all clients
but you can change their visibility: Object visibility | Unity Multiplayer Networking

1 Like