Search Issue Tracker
By Design
By Design in 2021.3.X
Votes
0
Found in
2021.3.31f1
Issue ID
UUM-53153
Regression
No
NavMeshAgent currentOffMeshLinkData.offMeshLink doesn't contain the current NavMeshLink
How to reproduce:
1. Download and open the attached "BetterNavMeshAgentRotation" project
2. Enter Play mode
3. Observe the console window
Expected outcome: No errors appear in the console window
Actual outcome: NullReferenceException errors appear in the console window
Reproducible with: 2021.3.31f1, 2022.3.11f1, 2023.1.16f1, 2023.0b13, 2023.3.0a9
Reproduced on: MacOS (Ventura 13.4)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Shader Graph Node information is briefly displayed in Graph Inspector when clicking on Category in the Blackboard
- Module installation fails with "Download failed: Validation Failed" errors when using beta.2 Hub version
- JsonConvert conversion fails trying to call GetCallbackMethodsForType when [OnDeserialized] is used in a class
- Shader Graph Category dropdown cannot be expanded/collapsed when clicking on the text
- Different text alignment in the column header in Entities "System" window
Resolution Note:
NavMeshAgent.currentOffMeshLinkData.offMeshLink returns a reference only to an OffMeshLink component, and not to a NavMeshLink component.
When the value of the NavMeshAgent.isOnOffMeshLink property is true but NavMeshAgent.currentOffMeshLinkData.offMeshLink is null, this indicates that the link is either a NavMeshLink or a type of Off-mesh link that has been automatically generated. In that situation the property `NavMeshAgent.navMeshOwner` can point to the component that has created the link, if that was the case.
Here is an example of code that retrieves the area type of the link that the agent traverses:
```
var _agent = GetComponent<NavMeshAgent>();
var linkAreaType = 2; // 2 is the Jump area used by all auto-generated links
if (_agent.currentOffMeshLinkData.offMeshLink != null)
{
linkAreaType = _agent.currentOffMeshLinkData.offMeshLink.area;
}
else
{
linkAreaType = _agent.navMeshOwner switch
{
NavMeshLink navMeshLink => navMeshLink.area,
OffMeshLink offMeshLink => offMeshLink.area,
_ => linkAreaType
};
}
```
----
Side note: Starting with 2023.2 the newly-added NavMeshAgent.currentOffMeshLinkData.owner property references the NavMeshLink or the OffMeshLink that has created the navigation link.
https://docs.unity3d.com/2023.2/Documentation/ScriptReference/AI.OffMeshLinkData-owner.html
Resolution Note (2021.3.X):
NavMeshAgent.currentOffMeshLinkData.offMeshLink returns a reference only to an OffMeshLink component, and not to a NavMeshLink component.
When the value of the NavMeshAgent.isOnOffMeshLink property is true but NavMeshAgent.currentOffMeshLinkData.offMeshLink is null, this indicates that the link is either a NavMeshLink or a type of Off-mesh link that has been automatically generated. In that situation the property `NavMeshAgent.navMeshOwner` can point to the component that has created the link, if that was the case.
Here is an example of code that retrieves the area type of the link that the agent traverses:
```
var _agent = GetComponent<NavMeshAgent>();
var linkAreaType = 2; // 2 is the Jump area used by all auto-generated links
if (_agent.currentOffMeshLinkData.offMeshLink != null)
{
linkAreaType = _agent.currentOffMeshLinkData.offMeshLink.area;
}
else
{
linkAreaType = _agent.navMeshOwner switch
{
NavMeshLink navMeshLink => navMeshLink.area,
OffMeshLink offMeshLink => offMeshLink.area,
_ => linkAreaType
};
}
```
----
Side note: Starting with 2023.2 the newly-added NavMeshAgent.currentOffMeshLinkData.owner property references the NavMeshLink or the OffMeshLink that has created the navigation link.
https://docs.unity3d.com/2023.2/Documentation/ScriptReference/AI.OffMeshLinkData-owner.html