#Command only working on host and not non-host clients?

21 messages · Page 1 of 1 (latest)

slow moat
#

I'm wondering if maybe I'm misunderstanding how Command works

{
    if (!isOwned) { return; }

    if (Input.GetMouseButtonDown(1))
    {
        Debug.Log("A");
        CmdRightClick();
    }
}

[Command]
private void CmdRightClick()
{
    Debug.Log("B");
    Ray ray = cam.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast(ray, out RaycastHit hit, 1024, clickMask))
    {
        MoveClick(hit);
    }
}

[Client]
private void MoveClick(RaycastHit hit)
{
    agent.SetDestination(hit.point);
    Debug.Log("C");
}

So I'm doing a basic right click to move mechanic here, but for some reason this only works on the host but not the non-host clients.
On Host the debug prints out A,B and C and on non host it's only A
There is no error or warnings on either
Am I approaching this wrong? My understanding is that Command is used from client to request the server to run the function

#

Not sure if relevant but here's my custom NetworkManager that is used to spawn

[SerializeField] private 
MatchSpawnPosition spawnA;

public override void OnStartClient()
{
    lobbyCamera.SetActive(false);
}

public override void OnStopClient()
{
    lobbyCamera.SetActive(true);
}

public override void OnServerAddPlayer(NetworkConnectionToClient conn)
{
    if (!NetworkClient.ready)
    {
        NetworkClient.Ready();
    }

    GameObject player = Instantiate(playerPrefab, spawnA.Points[Players.Count].position, spawnA.Points[Players.Count].rotation);
    NetworkServer.AddPlayerForConnection(conn, player);
}```
wind bramble
#

Your not passing over any parameters, your current setup presumes players all have cameras inside their player prefabs?

#

Any yellow warnings in console saying trying to send command without authority?

slow moat
slow moat
#

Only thing on console is those ABC debug above when the editor is host and only A if the editor is the non host

#

I did try to bypass authority by setting requires authority to false, still same issue

#

Not sure how helpful this is but here's the setup of the other components on the network manager object

wind bramble
#

So any player that sends command, will always use servers input.mouse position

#
private void Update()
{
    if (!isOwned) { return; }

    if (Input.GetMouseButtonDown(1))
    {
        Debug.Log("A");
        Ray ray = cam.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out RaycastHit hit, 1024, clickMask))
        {
            CmdRightClick(hit);
        }
    }
}

[Command]
private void CmdRightClick(RaycastHit hit)
{
    Debug.Log("B");
    MoveClick(hit)
}
#

@slow moat Makes sense?

slow moat
# wind bramble <@1105455301001494618> Makes sense?

Ah yep that does make sense, but it still didn't fix it unfortunately

When the editor is non host I still have the same issue of only A being printed but not B or C

I debugged hit.point in the Update during the raycast as well as at Debug B. I got the correct values for the Update but for B, it was 0,0,0. But I thought the values were being passed over by calling CmdRightClick(hit) in Update?

#

Regarding the hit.point debuggingn, I should point out this applies to both host and non-host
All players

#

An additional debugging I found that for both host and non host netIdentity.connectionToServer returned a connection but for the non host netIdentity.connectionToClient returned null
But since we made it past the isOwned check doesn't that mean the client is owned?

tall tangle
#

Which console are you checking? 'B' will only fire on the host console, not client editor console. Also you can't send a raycast hit through a command, mirror won't serialise that. Just send the raycast hit position as a vector3.

wind bramble
hearty beacon