Home

Awesome

Unity Technologies management should be ashamed of what they have done to all our work

When I wrote this code, Unity was still a promising game engine, one I was proud to work for.

Now that the shortsightedness of the c-suite there has flushed so much of our good work down the drain, it's hard to say that anyone should be excited about the engine, even though the C# job system remains an incredible accomplishment and developer experience.

John Riccitiello Can Suck My Dick And Balls

fuck you

actual readme below

C# Job System Cookbook

This is a repo of examples I've written to learn how to use the C# job system to write systems at scale, here for reference and sharing.

The goal of this repo is making it clearer how you can structure your data, schedule your jobs, and use the results. So, the examples use easy to understand problems & algorithms.

This repo does not cover using C# jobs with the Entity Component System. Please see the official example repo for more on that.

Each example script has a corresponding scene where it's set up.

Job System Details

You can use the job system in Unity 2018.x right now. I recommend 2018.2 for these examples now.

For a detailed look into how the C# job system works, please watch the Unite Austin presentation if you haven't seen it. There is also a Q & A from Unite Berlin in 2018

Examples

Note: examples in this repo use LateUpdate() as an easy way to handle completing jobs later than we schedule them, but in real code you might want to schedule the jobs early in Update (using Script Execution Order maybe) so you can use the result later in the same frame.

All examples demonstrate the use of persistently-allocated job memory.

Realtime Image Processing (with Burst compilation)

Process input from a webcam in real time using Burst-compiled jobs.

the job details are all in this file, and the above file is the main script.

This demo implements 5 different effects , all based around operating on a pixel only if it's color channel value is over some threshold

To change the color thresholds, select the WebcamDisplay in the heirarchy of the example scene & check out the Webcam Processing component. You can also change the scanline effect as well as select a webcam resolution that works for you there.

Change Mesh Vertices & Normals Every Frame

Modify all vertices & normals of a mesh in parallel every frame.

This is the most visually interesting example. Uses a more complex single job.

Change Mesh Vertices Every Frame

Modify all 20678 vertices of a mesh in parallel every frame, using Perlin noise & sin(time).

Uses a single job.

Accelerate 10000 Cubes

First determine velocities, then change positions based on those velocities.

Demonstrates using the TransformAccessArray, necessary for doing transform operations in jobs.

Point & Bounds Intersection Checks

Check a Vector3 and a Bounds for intersection against a list of 10000 Bounds.

Demonstrates running 2 independent jobs.

Ray / Bounds Intersection Checks

Check a Ray for intersection with a large Bounds array in two steps.

Demonstrates reducing an array of checks to a smaller list, and using temporarily-allocated job memory.

Point Cloud Generation & Processing

Generates a cloud of 10000 points, then calculates magnitudes & normalizes the points.

Further Examples

Keijiro Takahashi has a great example of using the job system with ECS