Error: “SetDestination” can only be called on an active agent that has been placed on a NavMesh. UnityEngine.AI.NavMeshAgent:set_destination(Vector3) WorldInteraction:GetInteraction() (at Assets/Scripts/WorldInteraction.cs:33) WorldInteraction:Update() (at Assets/Scripts/WorldInteraction.cs:16)
So i followed a video on Youtube "Level Design and Click to Move | Making a Simple RPG - Unity 5 Tutorial (Part 1) - YouTube"¨
I get this error and thats after baking, i’ve followed every step very closely and redone it multiple times, anyone know how this can be fixed?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WorldInteraction : MonoBehaviour {
UnityEngine.AI.NavMeshAgent playerAgent;
void Start()
{
playerAgent = GetComponent<UnityEngine.AI.NavMeshAgent>();
}
void Update()
{
if (Input.GetMouseButtonDown(0) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
GetInteraction();
}
void GetInteraction()
{
Ray interactionRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit interactionInfo;
if (Physics.Raycast(interactionRay, out interactionInfo, Mathf.Infinity))
{
GameObject interactedObject = interactionInfo.collider.gameObject;
if (interactedObject.tag == "interactable Object")
{
Debug.Log("Interactable interacted.");
}
else
{
playerAgent.destination = interactionInfo.point;
}
}
}
}