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:
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.
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.
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.
2. Install the OSC Jack package in Unity
First, open a Unity project (2021.3 or later). Click Edit and open Project Settings.
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:
Click Window and open the Package Manager.
Switch the package source to My Registries and then find OSC Jack and click Install to install the package.
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.
In the Assets folder of the Project, right-click > Create > ScriptableObjects > OSC Jack > Connection to create an OscConnection profile.
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.
Create an empty object GameManager and add the OSC Jack’s Event Receiver script. Follow these steps:
- Drag the OscConnection profile that you just added into the Connection property.
- Enter “/a1” in the OSC Address to receive the value that we created in TouchDesigner.
- Change the Data Type to String.
- 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.
Run the project. The value that is created in TouchDesigner will be synchronized to Unity in real time.
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.