> ## Documentation Index
> Fetch the complete documentation index at: https://docs.playbook3d.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Unity SDK

Playbook's Unity SDK integrates the editor with ComfyUI. It allows you to quickly create and refine textures for your
scene using generative diffusion models.

[Get the Unity SDK](https://github.com/playbook3d/playbook3d-unity-sdk)

## Adding Playbook To Your Project

> [!WARNING]
>
> The Unity SDK only works on projects that are using the Universal Render
> Pipeline. If your project is not using URP, you can add it by following this
> guide: [Installing URP into an existing
> Project](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@7.1/manual/InstallURPIntoAProject.html)

**1. Open up the Package Manager**

Once you have your Unity project open, go to Window -> Package Manager. In the package manager, click the plus
icon on the top left and click "Add package from git URL...".

![Add From Git](https://mintcdn.com/playbook/tkxhIHJ9EBsxTrRu/images/UnitySDK/AddGitPackage.png?fit=max\&auto=format\&n=tkxhIHJ9EBsxTrRu\&q=85\&s=28675f71875f4e6978e29f40069078e8)

**2. Add the package through Github**

Enter the link provided by our repository: [Unity SDK](https://github.com/playbook3d/playbook3d-unity-sdk)

![Github URL](https://mintcdn.com/playbook/tkxhIHJ9EBsxTrRu/images/UnitySDK/GithubRepo.png?fit=max\&auto=format\&n=tkxhIHJ9EBsxTrRu\&q=85\&s=063d567698d355eebcf61b23d89fe9bd)

**3. Add the dependency**

Playbook is dependent on `SocketIOUnity`, so make sure to also add it to your project using the same steps as
before: [Socket IO Unity](https://github.com/itisnajim/SocketIOUnity)

## How To Use Playbook

**1. Attach the PlaybookSDK component**

To begin using Playbook, simply attach the `PlaybookSDK` component to your main camera.

![PlaybookSDK Component](https://mintcdn.com/playbook/tkxhIHJ9EBsxTrRu/images/UnitySDK/PlaybookSDKComponent.png?fit=max\&auto=format\&n=tkxhIHJ9EBsxTrRu\&q=85\&s=d44d8a7b247f0974a557edec5849ed81)

**2. Add your API key**

Add your Playbook API key in the `Playbook Account API Key` field. You can grab your API key from your
[Playbook](https://beta.playbook3d.com/) account.

**3. Select your team + workflow**

Once you enter Play mode in Unity, the `Teams` and `Workflows` properties will be populated with your respective
teams and workflows. Select the ones you want to work with.

> [!WARNING]
>
> Note that you will need to exit and re-enter Play mode to refresh teams and workflows.

**4. Start capturing**

You can now start capturing a single frame or an image sequence by clicking the buttons.

You can check if your workflow was received by our servers by opening up the workflow you selected in the [Playbook Dashboard](https://beta.playbook3d.com).
Open up your browser's console and you should receive a queued run:

![Web Editor Console](https://mintcdn.com/playbook/tkxhIHJ9EBsxTrRu/images/UnitySDK/WebEditorConsole.png?fit=max\&auto=format\&n=tkxhIHJ9EBsxTrRu\&q=85\&s=4e892d21b8a085beaf71a2752afc4aba)

**5. Wait for the render**

Once the render is complete, you'll find the URL to your image in the `PlaybookSDK` component. Copy this link,
paste it on your local internet browser, and your image will start downloading.

![Image Result URL](https://mintcdn.com/playbook/tkxhIHJ9EBsxTrRu/images/UnitySDK/ImageResultURL.png?fit=max\&auto=format\&n=tkxhIHJ9EBsxTrRu\&q=85\&s=fabeb03637acf562b04000ed9b2e5085)

## Adding to Mask Pass

You can further customize your renders by manipulating the mask pass.
To add or remove GameObjects from mask groups, you can call the following methods:

> [!WARNING]
>
> GameObjects that do not have a `Renderer` component attached cannot be added
> to a mask group.

```cs theme={"dark"}

// To add
PlaybookSDK.AddObjectToMaskGroup(GameObject maskObject, MaskGroup maskGroup);
PlaybookSDK.AddObjectsToMaskGroup(List<GameObject> maskObjects, MaskGroup maskGroup);

// To remove
PlaybookSDK.RemoveObjectFromMaskGroup(GameObject maskObject);
PlaybookSDK.RemoveObjectsFromMaskGroup(List<GameObject> maskObjects);

```

Additionally, you can also change the mask group of the background through these methods:

```cs theme={"dark"}

// To add
PlaybookSDK.SetBackgroundMaskGroup(MaskGroup maskGroup);

// To remove
PlaybookSDK.RemoveBackgroundMaskGroup();

```

> [!NOTE]
>
> Playbook supports up to 7 mask groups which are specified by the `MaskGroup`
> property. `MaskGroup` also includes the "Catch-all" mask, which is the default
> group for objects that are not part of a mask group.

## Listening to Results Received

To listen to workflow results when they are received, you can subscribe to `ResultReceived()` given in `PlaybookSDK.cs`, which returns the result as a url `string`.

```cs theme={"dark"}
    private void OnEnable()
    {
        PlaybookSDK.ResultReceived += EventToDoWhenReceived;
    }

    private void OnDisable()
    {
        PlaybookSDK.ResultReceived -= EventToDoWhenReceived;
    }
```

## Overriding Node Inputs

If you would like to manually override node inputs, you can do so by using `OverrideNodeInputs()`
given in `PlaybookSDK.cs`.

To call `OverrideNodeInputs()`, you must provide a dictionary on inputs to override the desired Playbook nodes in your selected workflow, where the `key` is the node ID and the `value` is the new value. For example:

```cs theme={"dark"}
Dictionary<string, object> inputs = new Dictionary<string, object> {
                ["11"] = "cats in outer space",
            };
PlaybookSDK.OverrideNodeInputs(inputs);
```

Dashboard display of node IDs per workflow is in progress. Currently, node IDs can be found by opening browser console in the [Playbook Dashboard](https://beta.playbook3d.com) and searching for `"Playbook Nodes:"`.

![Find Node IDs](https://mintcdn.com/playbook/tkxhIHJ9EBsxTrRu/images/UnitySDK/NodeIDs.png?fit=max\&auto=format\&n=tkxhIHJ9EBsxTrRu\&q=85\&s=14215f15ba99dcc6f3c261031444bd3f)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.