Threading

I am trying to thread in C# and I am not used to C#, I program in Java.

I need to be able to have my AI pathfind while moving on a path. I am using arongranberg’s A* path project by the way.
I am new to the pathfinding part of game programming, so any help would be appreciated.

For threading look up C# threading tuts.

You may also want to look up Co-routines - It’s a unity feature that gives you some of the advantages of threading while remaining single threaded.

There are some implementations of A* already completed - Some in the asset store maybe some freebies - take a look at how they did it.,

Aron Granbergs A* in its pro version already has threading, so you might want to opt for that

I don’t have the extra funding to purchase an $100 pro version. I would rather just implement it myself.

@NPS
Thanks for the tips, I will definitely look into the Co-routines

Apologies for hijacking this thread, but this is somewhat relevant.

I’m rendering 500 or so indices on the fly (by creating and going through 32^2 vertices) and I’m experiencing a ‘jerk’ when these pieces of mesh are being generated. Is there any way to thread it not do this?

I’m curious if I’m jerking on the actual vertice part where everything is added to the list or if it’s this:

			subMesh.vertices = Vertices.ToArray();
        	subMesh.triangles = Indices.ToArray();
			subMesh.RecalculateNormals();

If it’s that, then I don’t think that can be threaded, as it interacts with Unity. Is that correct?

the jerking is pretty surely just one line and thats the recalculate :slight_smile:

if you feed it with the normals and don’t recalc it should go better.

but actually you can not thread any of this here aside the “ToArray” call, the rest is accessing a unity mesh and that can only happen from the normal thread

If I feed it with the normals? Can you expand on this?

the mesh has a normals array which you can fill with the corresponding normals for example :slight_smile:

Also, do you need ToArray? Why not generate an array to begin with?

–Eric