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

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 :
Click to See code

 private IEnumerator LoadSceneAndSetActive (string sceneName)
    {
        yield return SceneManager.LoadSceneAsync (sceneName, LoadSceneMode.Additive);

        Scene newlyLoadedScene = SceneManager.GetSceneAt (SceneManager.sceneCount - 1);
        SceneManager.SetActiveScene (newlyLoadedScene);
    }

But after new scene loaded, when i try to move my character, it throws this Error:
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 :
Click to see code

 public void OnGroundClick(BaseEventData data)
    {
        Debug.Log("OnGroundClick");
        PointerEventData pData = (PointerEventData)data;
        NavMeshHit hit;
        if (NavMesh.SamplePosition (pData.pointerCurrentRaycast.worldPosition, out hit, navMeshSampleDistance, NavMesh.AllAreas))
            destinationPosition = hit.position;
        else
            destinationPosition = pData.pointerCurrentRaycast.worldPosition;
        agent.SetDestination(destinationPosition);
        agent.isStopped = false;
    }

is there anyone who suggest a solution to this ?

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

EDIT:
problem wasn’t navmesh related… case closed.

Could you tell what the problem was ? I’m having the same issue…

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.

Dont listen to the user above, navmeshcomponents is out of date and is now inside of Unity. Its called NavMeshBuilder now.

!! Oh so that’s why the github project is apparently dead! As of which Unity version is this the case?

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.

Possibly, unity havent commented on whats up with that repo and if we should be using it anymore…

I decided to put my error-generating code into Try block:

 try
            {
                m.agent.isStopped = false;
                m.agent.SetDestination(m.destinationPosition);
            }
            catch
            {
            }

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) :slight_smile:

1 Like