How to Receive Values from Unity in TouchDesigner?

by

post on

TouchDesigner

In the previous article, we introduced How to use TouchDesigner’s OSC Out CHOP to send values to Unity. In this article, we will use OSC In CHOP to let TouchDesigner receive values from Unity.

We will use Unity’s Slider UI as an interactive interface, output a range of 0~1 values, and let TouchDesigner receive it via OSC.

The specific steps are as follows:

  1. Create a Slider UI in Unity.
  2. Connect the Slider UI to the Property Sender of OSC Jack.
  3. Create an OSC In CHOP in TouchDesigner.
  4. Start Unity and TouchDesigner.
  5. Slide the Slider UI in Unity, and TouchDesigner will receive the value and display it on the interface.
touchdesigner-get-value-from-unity-with-osc - touchdesigner get value from unity with osc 1 en

Steps

1. Install the OSC Jack package

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

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 OscConnection and change the Port to 10000, the default port for TouchDesigner.

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

2. Create UI

In the scene, create a Slider UI and adjust it to a suitable size. The default setting of the Slider object has a range of floating-point numbers 0~1, and no settings need to be modified.

touchdesigner-get-value-from-unity-with-osc - touchdesigner get value from unity with osc 3

3. Configure OSC

In the scene, create an empty object GameManager, first add the Property Sender script of OSC Jack, then drag the previously created OscConnection setting file to the Connection field, and finally drag the Slider UI we added to the Data Source field, and set Component to Slider and Property to value, please refer to the figure below for the settings.

touchdesigner-get-value-from-unity-with-osc - touchdesigner get value from unity with osc 4

4. Create OSC In CHOP in TouchDesigner

Open a new TouchDesigner project, delete all the default OP, add an OSC In and keep the default settings unchanged, and you can execute the test.

touchdesigner-get-value-from-unity-with-osc - touchdesigner get value from unity with osc 5

Test

Run the Unity project, use the mouse to drag the Slider in the screen, and the corresponding value will be directly reflected in TouchDesigner.

touchdesigner-get-value-from-unity-with-osc - touchdesigner get value from unity with osc 6

References