0

Using Unity, I want an Agent to path-find in a runtime generated scene. Normally, Unity provides a baked solution for path-finding, but I don't know how to implement it in runtime, or whether it is even possible.

How can I path-find in runtime with Unity?

Thank you for your help.

0

1 Answer 1

1

In Unity you can calculate a Path between two points using:

private NavMeshPath myPath; void Start () { myPath= new NavMeshPath(); } void SetPath() { NavMesh.CalculatePath(Vector3 sourcePosition, Vector3 targetPosition, int areaMask, NavMeshPath myPath); } 

Once you have the NavMeshPath myPath between two points, you can set that path to an agent:

NavMeshAgent.SetPath(NavMeshPath myPath); 

More about this here: https://docs.unity3d.com/530/Documentation/ScriptReference/NavMesh.CalculatePath.html https://docs.unity3d.com/530/Documentation/ScriptReference/NavMeshAgent.SetPath.html

Sign up to request clarification or add additional context in comments.

2 Comments

@JoseMartinez-Morales You are welcome. If it worked for you, would be nice it you accept my answer
What button should I press?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.