Navmesh agent doesn't work on client

I’m in multiplayer with mirror lecture11 I did everything like the tutorial and everything work great on host but in client there is no movement I checked every method with debug and every thing work except of this line:
agent.SetDestination(hit.position);

agent wasn’t null and I don’t know what is the problem

@Yitzchak_Cohen

Hi there,
Are you getting any errors in the console? Are you able to log the hit.position and see if it is accurate?

hi
I test that and in both client and server the hit.point value is same but it doesn’t work in client

Okay, I would check to make sure the input system is set to both in the player settings.

please go to Project Settings → Player → Other and make sure the Active Input Handling is set to both. Sometimes there is a bug where Unity resets this so make sure it is correct if you are still getting the error. Let me know if this helps.

I did what you said and didn’t worked
I found that The CmdMove method doesn’t call in client
I’m sure that it was working last time I checked . but now nothing happen in this method
this is my code

public class Movement : NetworkBehaviour
{
    [SerializeField]private NavMeshAgent agent = null;
    Camera maincam;

    #region server
    [Command]
    private void CmdMove(Vector3 position)
    {
        Debug.Log("in cmd move");
        if(!NavMesh.SamplePosition(position, out NavMeshHit hit,1f,NavMesh.AllAreas)) {Debug.Log("invalid area"); return; }
        agent.SetDestination(hit.position);
        Debug.Log("valid area");
    }
    #endregion

    #region client
    public override void OnStartAuthority()
    {
        base.OnStartAuthority();
        maincam = Camera.main;
    }


    [ClientCallback]
    private void Update()
    {
        if(!isOwned) { return; }

        if (!Input.GetMouseButtonDown(1)) { return; }

        Ray ray = maincam.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity))
        {
            Debug.Log(hit.point + "  gh  " + Input.mousePosition);
            CmdMove(hit.point);
            Debug.Log("hiiiiiiii");
            if (agent == null || maincam == null) { Debug.Log("Null"); }
        }
    }

    #endregion

Even I tried to make the command to [Command(requiersAuthority = false)]

Can you confirm how far in the update method you are getting? Is it passing the isOwned check, the Input check and the Raycast check? Are there any errors in the console?

every time i click on ground i get all the debug.Log in console and there is no error except of this warning :

No Transport assigned to Network Manager - Using Telepathy (inactive/disconnected) found on same object.
UnityEngine.Debug:LogWarning (object)
Mirror.NetworkManager:InitializeSingleton () (at Assets/Mirror/Core/NetworkManager.cs:693)
Mirror.NetworkManager:Awake () (at Assets/Mirror/Core/NetworkManager.cs:198)

I have telepathy transport attached to network manager gameobject
raycast and input all work but the only problem here is that the CmdMove Method is not called

I solved this by adding a MonoBehaviour class instead of networkbehaviour for movement and add it to player. it worked without any problem
I don’t know why Nathan didn’t used that for movement maybe because of educational purposes

I made a new project and wrote a simple code
but have the same problem it doesn’t work in client and everything is fine in host

//I test with requiresAuthority = false and requiresAuthority = true
    [Command(requiresAuthority = false)]
    private void CmdTest()
    {
        Debug.Log("In Cmd Method");
    }


    [ContextMenu("Click TO Test")]
    public void TestThis()
    {
        Debug.Log("In context menu");
        CmdTest();
    }

just there is a warning in console as before :
No Transport assigned to Network Manager - Using Telepathy (inactive/disconnected) found on same object.
UnityEngine.Debug:LogWarning (object)

and i have telepathy transport attached to network manager

Hmm, it’s possible you were successfully calling CmdMove, but the movement was being overridden. (remember you would only see the debug inside of CmdMove on the server build, as commands are called on the server).
That No Transport bug is strange. You need to both have Telepathy attached to the NetworkManager and drag and drop the attached Telepathy into the Transport field on the NetworkManager. Did you do both of those?

It didn’t work
shouldn’t we use a command and a ClientRpc ?
this is my network manager setup

Using a Command and a ClientRPC would be circular. You just need to send the movement command to the server. The server validates the movement and then updates the NetworkTransform, which is synced back to all the clients. Send a ClientRPC to handle movement would be redudant.

Is it possible you have 2 network managers in the scene?

I don’t know what happen there I get the warning that I have two network Manager
but I couldn’t find the second one
any way I left the last section of chapter1 and moved to next chapter and I don’t have this error
and I’m really appreciate to you because of your generous help

The two network managers can happen when you have two scenes and they both have managers. The first scene loads, and the networkManager is set to do not destroy, so it persists into the second scene. When the second scene loads then there are two of them and it throws an error then destroys the extra one.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms