Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

[Solved]Additive Scene NavMesh Problem >"SetDestination" can only be called Error...

Discussion in 'Navigation' started by NorthStar79, May 6, 2017.

  1. NorthStar79

    NorthStar79

    Joined:
    May 8, 2015
    Posts:
    87
    Hello all,
    i hope you have a great day, i came up a problem when using NavMesh with Additive Scenes.
    Here is what i try to accomplish;
    i have a character that i set as NavMesh agent in my first Scene.
    when player clikcs a button it calls this function :
    Code (CSharp):
    1.  private IEnumerator LoadSceneAndSetActive (string sceneName)
    2.     {
    3.         yield return SceneManager.LoadSceneAsync (sceneName, LoadSceneMode.Additive);
    4.  
    5.         Scene newlyLoadedScene = SceneManager.GetSceneAt (SceneManager.sceneCount - 1);
    6.         SceneManager.SetActiveScene (newlyLoadedScene);
    7.     }
    But after new scene loaded, when i try to move my character, it throws this Error:
    "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
    PlayerMovement:OnGroundClick(BaseEventData) (at Assets/_Scripts/MonoBehaviours/Player/PlayerMovement.cs:89)
    UnityEngine.EventSystems.EventSystem:Update()

    &&

    "Resume" can only be called on an active agent that has been placed on a NavMesh.
    UnityEngine.AI.NavMeshAgent:set_isStopped(Boolean)
    PlayerMovement:OnGroundClick(BaseEventData) (at Assets/_Scripts/MonoBehaviours/Player/PlayerMovement.cs:90)
    UnityEngine.EventSystems.EventSystem:Update()
    and here is the my movement script's related part to this Error :
    Code (CSharp):
    1.  public void OnGroundClick(BaseEventData data)
    2.     {
    3.         Debug.Log("OnGroundClick");
    4.         PointerEventData pData = (PointerEventData)data;
    5.         NavMeshHit hit;
    6.         if (NavMesh.SamplePosition (pData.pointerCurrentRaycast.worldPosition, out hit, navMeshSampleDistance, NavMesh.AllAreas))
    7.             destinationPosition = hit.position;
    8.         else
    9.             destinationPosition = pData.pointerCurrentRaycast.worldPosition;
    10.         agent.SetDestination(destinationPosition);
    11.         agent.isStopped = false;
    12.     }

    is there anyone who suggest a solution to this ?

    thanks for your time for reading my question.
    cheers :)


    EDIT:
    problem wasn't navmesh related.. case closed.
     
    Last edited: May 6, 2017
  2. FrozenBotsStudio

    FrozenBotsStudio

    Joined:
    Jun 27, 2016
    Posts:
    10
    Could you tell what the problem was ? I'm having the same issue...
     
  3. NorthStar79

    NorthStar79

    Joined:
    May 8, 2015
    Posts:
    87
    I am still working on same project since then but i can not really remember how i did solve this problem. but try to move your player to new scene like this " SceneManager.MoveGameObjectToScene(); " hope it helps, if its not . i highly recommend using this navigation system: " https://github.com/Unity-Technologies/NavMeshComponents " if its not too late to change , unfortunately it was too late for me.
     
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,421
    Dont listen to the user above, navmeshcomponents is out of date and is now inside of Unity. Its called NavMeshBuilder now.
     
  5. IngeJones

    IngeJones

    Joined:
    Dec 11, 2013
    Posts:
    129
    !! Oh so *that's* why the github project is apparently dead! As of which Unity version is this the case?
     
  6. IndubhushanDas

    IndubhushanDas

    Joined:
    Feb 19, 2014
    Posts:
    115
    I've got the same errors:
    though my agents (enemies) are moving.

    Can these erros be due to using NavMeshComponents? I use these to make navmeshbuild at runtime, because I have level generator.
     
  7. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,421
    Possibly, unity havent commented on whats up with that repo and if we should be using it anymore...
     
  8. IndubhushanDas

    IndubhushanDas

    Joined:
    Feb 19, 2014
    Posts:
    115
    I decided to put my error-generating code into Try block:
    Code (CSharp):
    1.  try
    2.             {
    3.                 m.agent.isStopped = false;
    4.                 m.agent.SetDestination(m.destinationPosition);
    5.             }
    6.             catch
    7.             {
    8.             }
    and it doesn't generate errors, and works as expected. so I'm happy on this. (maybe this will help anyone else with same errors) :)
     
unityunity