Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

421
Visualizações
Unable to use server command from client using unity mirror

Im trying to make a smart usable object system.
When the player is getting close to one of the usable items he will be able to press a button and use this specific item. everything works except for the use command execution;

using UnityEngine;
using Mirror;

public class Usable : NetworkBehaviour
{
    public void Use(GameObject[] allUsables, Player CurrentClient, GameObject[] vents = null)
    {
        if (CurrentClient.isLocalPlayer)
        {
            //this.GetComponent<NetworkIdentity>().AssignClientAuthority(CurrentClient.GetComponent<NetworkIdentity>().connectionToClient);
            switch (this.name)
            {
                case string name when name.Contains("EmergencyButton"):
                    Debug.Log("Reached Log Point");
                    CmdEmergencyButton();
                    break;
                default:
                    Debug.LogError("Not possible!");
                    break;
            }
            //this.GetComponent<NetworkIdentity>().RemoveClientAuthority();
        }
    }

    [Command]
    private void CmdEmergencyButton()
    {
        RpcEmergency();
    }

    [ClientRpc]
    private void RpcEmergency()
    {
        //Activates emergency button effect
        GameObject.Find("EmergencyButton").transform.GetChild(0).gameObject.SetActive(true);
    }
}

And calling the use function like this:

[Client]
void ActivateUse()
{
    if(isLocalPlayer)
    {
        Debug.Log("Client using");
        //currUsables has all the nearby usable objects
        GameObject currentToUse = GameObject.Find(currUsables[0].name);
        //Using that object.
        currentToUse.GetComponent<Usable>().Use(allUsables, this, allVents);
    }
}

From player object.
When calling CmdEmergencyButton() nothing happens except for this warning in the console;
Click to see warning

Trying to send command for object without authority. Usable.CmdEmergencyButton
UnityEngine.Logger:Log(LogType, Object)

I have tried giving authority to the client to use command from this object (comments in use function) but still nothing.
Any idea why it doesn't work?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda