Skip to content

Commit

Permalink
fix(Locomotion): prevent null reference in teleporter
Browse files Browse the repository at this point in the history
Check for null target before checking to see if it's a player or ui.
  • Loading branch information
jamre authored and thestonefox committed Jun 9, 2018
1 parent 649a42a commit cca532f
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions Assets/VRTK/Source/Scripts/Locomotion/VRTK_BasicTeleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,24 @@ public virtual void ToggleTeleportEnabled(bool state)
/// <returns>Returns `true` if the target is a valid location.</returns>
public virtual bool ValidLocation(Transform target, Vector3 destinationPosition)
{
//If the target is one of the player objects or a UI Canvas then it's never a valid location
if (VRTK_PlayerObject.IsPlayerObject(target.gameObject) || target.GetComponent<VRTK_UIGraphicRaycaster>())
//If the target is null, one of the player objects, or a UI Canvas then it's never a valid location
if (target == null || VRTK_PlayerObject.IsPlayerObject(target.gameObject) || target.GetComponent<VRTK_UIGraphicRaycaster>())
{
return false;
}

bool validNavMeshLocation = false;
if (navMeshData != null)
{
if (target != null)
{
NavMeshHit hit;
validNavMeshLocation = NavMesh.SamplePosition(destinationPosition, out hit, navMeshData.distanceLimit, navMeshData.validAreas);
}
NavMeshHit hit;
validNavMeshLocation = NavMesh.SamplePosition(destinationPosition, out hit, navMeshData.distanceLimit, navMeshData.validAreas);
}
else
{
validNavMeshLocation = true;
}

return (validNavMeshLocation && target != null && !(VRTK_PolicyList.Check(target.gameObject, targetListPolicy)));
return (validNavMeshLocation && !(VRTK_PolicyList.Check(target.gameObject, targetListPolicy)));
}

/// <summary>
Expand Down

0 comments on commit cca532f

Please sign in to comment.