Hello Click to walk.. help <3

Hello, I have a problem, my script dose not find my NavMeshAgent
I have a Agent on the “player” but …

Failed to create agent because there is no valid NavMesh … This comes up when i test start the game, and when i click the Area

“SetDestination” can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
PlayerMotor:MoveToPoint(Vector3) (at Assets/Scripts/PlayerMotor.cs:19)
PlayerController:Update() (at Assets/Scripts/PlayerController.cs:28)

This is my scripts

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour {

    public LayerMask movementMask;

    Camera cam;
    PlayerMotor motor;

    // Use this for initialization
    void Start () {
        cam = Camera.main;
        motor = GetComponent<PlayerMotor> ();
    }

    void Update () {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100, movementMask))
            {
                //Debug.Log ("We hit" + hit.collider.name + " " + hit.point);
                motor.MoveToPoint(hit.point);
            }
        }
    }

}

And the other …

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;


[RequireComponent(typeof(NavMeshAgent))]
public class PlayerMotor : MonoBehaviour {

    NavMeshAgent agent;

    // Use this for initialization
    void Start () {
        agent = GetComponent<NavMeshAgent>();
    }
  
    public void MoveToPoint (Vector3 point)
    {
        agent.SetDestination(point);
    }
}

That error sounds like you’ve not baked the navmesh in the scene.

Yes, got it Tnx it works now ;D haha Tnx so much

No prob :slight_smile: Glad it’s working for ya.

1 Like