How to Send Values from TouchDesigner to Unity?

by

post on

TouchDesigner

In this article, we will discuss how to send values from TouchDesigner to Unity. We will first create a constantly changing value in TouchDesigner. Then, we will use the OSC CHOP to send the value to Unity over UDP. Finally, we will use Unity’s UI to display the received data.

TouchDesigner is a visual programming language and development environment that is used to create interactive experiences. It is a popular choice for artists and designers because it is easy to use and allows for a high degree of customization.

Although I mainly use Unity for project development, TouchDesigner is still a very convenient tool for prototyping. It has built-in modules for common hardware such as Hokuyo and Kinect, which allows me to prototype in TouchDesigner before I can connect the hardware in Unity.

The basic architecture is as follows:

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 1 en

Steps

1. Create and name a value in TouchDesigner

Launch TouchDesigner and open a default project. The Noise CHOP can be used as a value generator, so connect the Rename and OSC Out CHOPs to the Noise CHOP.

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 02

Click on the Rename CHOP and set the To property to a1 or any name you want. This OP renames the value, so in this step it will rename the chan1 value from Noise to a1.

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 03

Finally, click on the OSC Out CHOP and leave all the settings as default. We need to record the Network Address and Network Port properties so that Unity can connect to TouchDesigner successfully.

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 04

2. Install the OSC Jack package in Unity

First, open a Unity project (2021.3 or later). Click Edit and open Project Settings.

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 05

Switch to the Package Manager tab and register a package source in the Scoped Registries. Click Save to save the changes and close the Project Settings window.

The properties are as follows:

NameKeijiro
URLhttps://registry.npmjs.com
Scope(s)jp.keijiro
touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 06

Click Window and open the Package Manager.

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 07

Switch the package source to My Registries and then find OSC Jack and click Install to install the package.

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 08

3. Receive and display values in Unity

Create a Text (Legacy) object in the Canvas. Adjust the font color and size to make it more visible.

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 09

In the Assets folder of the Project, right-click > Create > ScriptableObjects > OSC Jack > Connection to create an OscConnection profile.

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 10

Click on the OscConnection and change the Port to the port that you set when you created the OSC Out in TouchDesigner. Since we did not change the default settings when we created the OSC Out CHOP, we can set the OscConnection’s Port to 10000 in this step.

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 11

Create an empty object GameManager and add the OSC Jack’s Event Receiver script. Follow these steps:

  1. Drag the OscConnection profile that you just added into the Connection property.
  2. Enter “/a1” in the OSC Address to receive the value that we created in TouchDesigner.
  3. Change the Data Type to String.
  4. Create an event listener for the String Event and drag in the Text (Legacy) object that you just created. Select the Dynamic string’s text property.
touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 12
touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 13

Test

Run the project. The value that is created in TouchDesigner will be synchronized to Unity in real time.

touchdesigner-send-value-to-unity-with-osc - touchdesigner send value to unity with osc 14

In this article, we have completed the task of sending values from TouchDesigner to Unity. In the next article, we will implement the reverse process of sending values from Unity to TouchDesigner.

References