Can't call RPC functions

Hi guys,
I’m using unity network with a dedicated server (no player is hosting).

I’m using command and rpc for a while but always with player objects, for the first time, I need to set up some kind of LevelManager. For what I understand so far, I need to instantiate it with a network identity component with NetworkServer.Spawn.

This manager is correctly registered in the network manager as a prefab.

Anyway, I just don’t get any debug clients side, the rpc function doesn’t seem to be called at all.Here is my code, anyone can point out the error ?

using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityEngine.Networking.NetworkSystem;
using System;
using System.Collections;

public class Timer : NetworkBehaviour
{
    public int timeLeft;
    public int gameDuration = 120;
    public Text timeText;

    // Use this for initialization
    void OnEnable()
    {
        timeText=GameObject.FindGameObjectWithTag("LevelTimer").GetComponent<Text>();
        timeLeft = gameDuration;
        if (isServer)
        {
            RpcUpdateTime(timeLeft);
            Countdown();
        }
    }
    private IEnumerator Countdown()
    {
        while (timeLeft > 0)
        {
            timeLeft--;
            RpcUpdateTime(timeLeft);
            yield return new WaitForSeconds(1);
        }
        RpcTimeUp();
    }

    [ClientRpc]
    void RpcUpdateTime(int time){
        timeLeft = time;
        timeText.text = timeLeft.ToString("0.00") + "s";
    }

    [ClientRpc]
    void RpcTimeUp()
    {
        Debug.Log("Time's Up !");
    }
}

Thanks u all ! :wink:

Try this, i think, call Rpc via a Cmd, it should work i think:

using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityEngine.Networking.NetworkSystem;
using System;
using System.Collections;

public class Timer : NetworkBehaviour
{
    public int timeLeft;
    public int gameDuration = 120;
    public Text timeText;

    // Use this for initialization
    void OnEnable()
    {
        timeText=GameObject.FindGameObjectWithTag("LevelTimer").GetComponent<Text>();
        timeLeft = gameDuration;
        if (isServer)
        {
            CmdUpdateTime(timeLeft);
            Countdown();
        }
    }
    private IEnumerator Countdown()
    {
        while (timeLeft > 0)
        {
            timeLeft--;
            RpcUpdateTime(timeLeft);
            yield return new WaitForSeconds(1);
        }
        CmdTimeUp();
    }

    [Command]
    void CmdUpdateTime(int time){
        RpcUpdateTime (time);
    }

    [ClientRpc]
    void RpcUpdateTime(int time){
        timeLeft = time;
        timeText.text = timeLeft.ToString("0.00") + "s";
    }

    [Command]
    void CmdTimeUp () {
        RpcTimeUp ();
    }

    [ClientRpc]
    void RpcTimeUp()
    {
        Debug.Log("Time's Up !");
    }
}

I don’t think it would, to my knowledge Cmd can’t be call from Server but from Client.
Of course, I probably could call a cmd from a client and make this cmd call a rpc but it looks like a ugly turnaround :

I really don’t understand why the hell I can’t call my ClientRpc directly since I check that the function is called server-side ! ^^’