NatCorder
Search…
Getting Started
Up and Running in No Time

Importing NatCorder

To begin, import the API with the Unity Package Manager by adding the following items to your Packages/manifest.json file:
1
{
2
// Add the NatML package registry
3
"scopedRegistries": [
4
{
5
"name": "NatML",
6
"url": "https://registry.npmjs.com",
7
"scopes": ["ai.natml"]
8
}
9
],
10
// Add NatCorder
11
"dependencies": {
12
"ai.natml.natcorder": "1.8.4"
13
}
14
}
Copied!

Specifying your Access Key

In order to use NatCorder, you need a NatML access key, along with an active Cloud Plan subscription. Retrieve your access key from NatML Hub:
https://hub.natml.ai/profile
Retrieve your access key on NatML Hub.
Once you have your access key, add it in Project Settings > NatML:
Specifying your NatML access key in Project Settings.
You must be on the NatML Cloud plan to use NatCorder.

Recording the Camera

Once the API is imported, you can begin to write recording code. Let's create a recorder to record a WebCamTexture.
RecordWebCam.cs
1
using UnityEngine;
2
using System.Threading.Tasks;
3
using NatML.Recorders;
4
5
public class RecordWebCam : MonoBehaviour {
6
7
async void Start () {
8
// Start the webcam
9
var cameraTexture = new WebCamTexture();
10
cameraTexture.Play();
11
// Wait for user to smile :)
12
await Task.Delay(2000);
13
// Create a recorder
14
var recorder = new GIFRecorder(
15
cameraTexture.width, // image width
16
cameraTexture.height, // image height
17
0.1f // frame duration in seconds
18
);
19
// Record 20 frames
20
for (var i = 0; i < 20; i++) {
21
// Commit frame
22
recorder.CommitFrame(cameraTexture.GetPixels32());
23
// Wait a bit before next commit
24
await Task.Delay(150);
25
}
26
// All done
27
var path = await recorder.FinishWriting();
28
}
29
}
Copied!
Add this component to any game object in your scene and enter Play mode. After about 5 seconds, you should find a .gif file sitting in your project folder!
This is the general pattern you will follow when working with NatCorder. Before going into more details, look through the minimum requirements for developing with and deploying NatCorder.