Asynchronous raycasting and pathfinding

Hi,
I’ve just downloaded the new Unity (beta) 2018.1b version and I’m wondering how to use all the new fancyness introduced, like the two things mentioned in the topic. Can I just put pathfinding and raycasting code into IJob.Execute method definition and it will just work, or are there some more specialized structs I need to extend in order for those two to work (like IJobParallelForTransform)?

Hi,
The existing NavMesh functionality cannot be used within IJobs. New methods for pathfinding, compatible with IJob, will be made available soon, in a beta release of Unity 2018.1. Scripting reference will be added to serve as entry point for learning about the new methods.
Regarding raycasts in IJobs, they will be made available much later, in future versions of Unity.

Later edit: Here I was referring to NavMesh raycasts.

I guess you mean next beta release? (I’m already using 2018.1 beta)

And as for the raycasting part - roadmap mentions it as a part of 2018.1 release, so by saying “future versions of Unity” do you mean some next beta, or, say, Unity 2019.1? :slight_smile:

This is a bit disappointing, as the roadmap showed everything on track :confused:

It will come during the 2018.1 beta period. Most likely in 18.1 beta 4.

4 Likes

This is great news :slight_smile:

any example?

Thanks~,and how about pathfinding.

For pathfinding please check out the methods in the new NavMeshQuery struct: Unity - Scripting API: NavMeshQuery

There are no examples provided yet.

Has anyone figured out how to do pathfinding with the new NavMeshQuery? I god to the point where you get the path result ( NativeSlice of PolygonIds ) and have no idea how to proceed further.
Code

var start = query.MapLocation( currentPos, Vector3.one * 3f, 0 );
var end = query.MapLocation( targetPos, Vector3.one * 3f, 0 );

var status = PathQueryStatus.Failure;
status = query.BeginFindPath( start, end );

if (status != PathQueryStatus.InProgress)
    return;

int performedIterations = 0;
int maxIterations = 1024;

 do
 {
     int iterations;
     status = query.UpdateFindPath( 32, out iterations );
     performedIterations += iterations;

    if (status == PathQueryStatus.Failure || status == PathQueryStatus.OutOfNodes)
        return;

} while (status != PathQueryStatus.Success && performedIterations < maxIterations);

int pathSize;
status = query.EndFindPath( out pathSize );
if (status == PathQueryStatus.Failure)
    return;

var array = new NativeArray<PolygonId>( pathSize, Allocator.Temp);
var path = new NativeSlice<PolygonId>( array );
var nodeCount = query.GetPathResult( path );
2 Likes

There is quite a bit of work to do for that api to be usable. This post illustrates what the portals represent and then an algorithm for creating a straight path using them.