"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
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 "https://www.youtube.com/watch?v=36ruPSD7FJk&t=2351s"¨
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;
}
}
}
}
Answer by Rubzen · Apr 14, 2017 at 08:53 PM
I've also tried placing the player closer to the ground.