What is the primary purpose of the NavMesh Agent component in Unity?
The NavMesh Agent component allows a GameObject to navigate a scene by following a path on a NavMesh, enabling automatic movement and obstacle avoidance.
Click to reveal answer
beginner
Which Unity system must be set up before using a NavMesh Agent?
A NavMesh must be baked in the scene. This is a navigation mesh that defines walkable surfaces for the agent.
Click to reveal answer
beginner
How do you make a NavMesh Agent move to a specific position in code?
Use the method agent.SetDestination(targetPosition); where agent is the NavMesh Agent component and targetPosition is a Vector3 coordinate.
Click to reveal answer
beginner
What property of NavMesh Agent controls how fast the agent moves?
The speed property controls the movement speed of the NavMesh Agent.
Click to reveal answer
intermediate
How does the NavMesh Agent avoid obstacles while moving?
The NavMesh Agent uses the NavMesh's data and built-in obstacle avoidance algorithms to find paths around obstacles automatically.
Click to reveal answer
What must be created in a Unity scene before a NavMesh Agent can navigate?
AA Collider component
BA Rigidbody component
CA Particle System
DA NavMesh baked on the scene
✗ Incorrect
The NavMesh defines walkable areas for the NavMesh Agent to navigate.
Which method moves a NavMesh Agent to a target position?
Aagent.MoveTo(targetPosition)
Bagent.SetDestination(targetPosition)
Cagent.Navigate(targetPosition)
Dagent.GoTo(targetPosition)
✗ Incorrect
SetDestination tells the NavMesh Agent where to move.
What property controls how fast a NavMesh Agent moves?
Aspeed
Bvelocity
Cacceleration
Dmass
✗ Incorrect
The speed property sets the movement speed of the agent.
How does a NavMesh Agent handle obstacles in its path?
AIt automatically finds a path around them
BIt ignores obstacles
CIt jumps over obstacles
DIt stops immediately
✗ Incorrect
The agent uses obstacle avoidance to navigate around obstacles.
Which Unity component is required on a GameObject to use NavMesh Agent features?
AAudio Source component
BAnimator component
CNavMesh Agent component
DLight component
✗ Incorrect
The NavMesh Agent component enables navigation behavior.
Explain how to set up and use a NavMesh Agent to move a character to a point in Unity.
Think about the steps from scene preparation to code control.
You got /4 concepts.
Describe how the NavMesh Agent component helps with obstacle avoidance during navigation.
Focus on how the agent moves safely in the environment.
You got /4 concepts.
Practice
(1/5)
1. What is the primary purpose of the NavMeshAgent component in Unity?
easy
A. To handle user input for character movement
B. To create 3D models for characters
C. To move characters smoothly using pathfinding on a navigation mesh
D. To play animations on characters
Solution
Step 1: Understand NavMeshAgent role
The NavMeshAgent component is designed to move objects smoothly on a navigation mesh, handling pathfinding and obstacle avoidance.
Step 2: Compare options
Options B, C, and D describe unrelated functions like modeling, input, and animation, which are not NavMeshAgent's job.
Final Answer:
To move characters smoothly using pathfinding on a navigation mesh -> Option C
Quick Check:
NavMeshAgent moves objects on NavMesh = A [OK]
Hint: NavMeshAgent moves objects using pathfinding on NavMesh [OK]
Common Mistakes:
Confusing NavMeshAgent with animation or input components
Thinking NavMeshAgent creates models
Assuming NavMeshAgent handles user controls
2. Which of the following is the correct way to set a destination for a NavMeshAgent named agent in C#?
easy
A. agent.MoveTo(new Vector3(10, 0, 5));
B. agent.Navigate(new Vector3(10, 0, 5));
C. agent.GoTo(new Vector3(10, 0, 5));
D. agent.SetDestination(new Vector3(10, 0, 5));
Solution
Step 1: Recall NavMeshAgent method for destination
The correct method to set a destination is SetDestination, which takes a Vector3 position.
Step 2: Check method names
Methods like MoveTo, GoTo, and Navigate do not exist on NavMeshAgent.
Final Answer:
agent.SetDestination(new Vector3(10, 0, 5)); -> Option D
Quick Check:
SetDestination sets target position = B [OK]
Hint: Use SetDestination with Vector3 to move NavMeshAgent [OK]
Common Mistakes:
Using non-existent methods like MoveTo or GoTo
Forgetting to use Vector3 as parameter
Confusing SetDestination with transform.position
3. Given the code below, what will be the output in the Unity Console?
using UnityEngine;
using UnityEngine.AI;
public class MoveAgent : MonoBehaviour
{
public NavMeshAgent agent;
void Start()
{
agent = GetComponent<NavMeshAgent>();
Vector3 target = new Vector3(5, 0, 5);
bool result = agent.SetDestination(target);
Debug.Log(result);
}
}
medium
A. True
B. False
C. NullReferenceException error
D. No output
Solution
Step 1: Understand SetDestination return value
The SetDestination method returns true if the destination is valid and reachable on the NavMesh.
Step 2: Analyze given target and agent
The target (5,0,5) is a valid position assuming the NavMesh covers it, so SetDestination returns true and logs it.
Final Answer:
True -> Option A
Quick Check:
SetDestination success returns true = C [OK]
Hint: SetDestination returns true if path is valid [OK]
Common Mistakes:
Assuming SetDestination returns void
Expecting false without checking NavMesh coverage
Ignoring possible NullReference if agent not assigned
4. What is wrong with the following code snippet that tries to move a NavMeshAgent?
public NavMeshAgent agent;
void Update() {
Vector3 destination = new Vector3(10, 0, 10);
agent.SetDestination(destination);
}
medium
A. SetDestination requires a NavMeshPath parameter
B. Calling SetDestination every frame can cause performance issues
C. NavMeshAgent must be moved using transform.position
D. The destination vector is invalid
Solution
Step 1: Review usage of SetDestination in Update
Calling SetDestination every frame is unnecessary and can cause performance overhead because the agent recalculates path repeatedly.
Step 2: Check other options
The destination vector is valid, NavMeshAgent should not be moved by transform.position, and SetDestination takes a Vector3, not NavMeshPath.
Final Answer:
Calling SetDestination every frame can cause performance issues -> Option B
Quick Check:
SetDestination in Update causes overhead = D [OK]
Hint: Avoid calling SetDestination every frame; call only on target change [OK]
Common Mistakes:
Moving agent by changing transform.position directly
Passing wrong parameter types to SetDestination
Ignoring performance impact of repeated calls
5. You want a NavMeshAgent to move to a target only if the path is valid and complete. Which code snippet correctly checks this before moving the agent?
NavMeshPath path = new NavMeshPath();
Vector3 target = new Vector3(7, 0, 7);
// Which code is correct?
hard
A. if (agent.CalculatePath(target, path) && path.status == NavMeshPathStatus.PathComplete) {
agent.SetDestination(target);
}
B. if (agent.SetDestination(target)) {
agent.CalculatePath(target, path);
}
C. agent.SetDestination(target);
if (path.status == NavMeshPathStatus.PathComplete) {
// do nothing
}
D. if (path.status == NavMeshPathStatus.PathPartial) {
agent.SetDestination(target);
}
Solution
Step 1: Understand path calculation and status check
Use CalculatePath to check if a path to the target exists and is complete before setting destination.
Step 2: Analyze each option
if (agent.CalculatePath(target, path) && path.status == NavMeshPathStatus.PathComplete) {
agent.SetDestination(target);
} correctly calls CalculatePath and checks path.status before SetDestination. Others either call methods in wrong order or check wrong status.
Final Answer:
if (agent.CalculatePath(target, path) && path.status == NavMeshPathStatus.PathComplete) {
agent.SetDestination(target);
} -> Option A
Quick Check:
CalculatePath + PathComplete check before SetDestination = A [OK]
Hint: CalculatePath and check PathComplete before SetDestination [OK]
Common Mistakes:
Calling SetDestination before checking path validity
Ignoring path.status or checking wrong status
Confusing CalculatePath and SetDestination roles
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.