# Control UE through OSC

## Overview

You can use OSC to do many things. We are going to create a layer in Live FX and use it to drive our Sun in Unreal Engine.&#x20;

Live FX currently has one way of using OSC that uses the first layer's Canvas transform controls, to control custom properties in Unreal Engine via a blueprint the user can set up.

There are a total of 8 float values that can be used in Unreal Engine, they correspond to the following properties in the Canvas menu (of the top dummy layer).&#x20;

The numbers here correspond to the Index numbers in the **Get OSC Message Float At Index** node in Unreal Engine:

<figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2F1W9fOhm4pUgw3kXnwLry%2Fimage.png?alt=media&#x26;token=278ef18e-0d4e-4f3a-94a9-9909582d33c0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FGsWcNNgXM6o0BFKOGrqP%2Fimage.png?alt=media&#x26;token=5d4cde69-fd09-4f6f-b34b-8bd9e2496471" alt=""><figcaption></figcaption></figure>

You can set these numbers to control many different areas of your Unreal Engine Scene, but for us, the default settings we will use will be to reserve 0 for Sky Light Intensity and we'll reserve 5,6,7 for Intensity and location in the sky:\
&#x20;

0: Sky Light Intensity \
5: Directional Light Intensity\
6: Directional Light Pitch\
7: Directional Light Roll

<figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FucaDAK3E65tB37TXKh4d%2Fimage.png?alt=media&#x26;token=bc4a1721-09b6-49e7-8755-b19655498238" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FE9JfToUieylBQFG8N7yx%2Fimage.png?alt=media&#x26;token=81c331db-b530-4a57-ac02-2388ff02bf1d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FpnkHxwszRaMFMnv9dZTS%2Fimage.png?alt=media&#x26;token=56633e39-088b-4a29-86be-f0647cf2bb43" alt=""><figcaption></figcaption></figure>

## Set up Live FX

1. Go to Live FX Menu>Live Links

2. Turn on OSC Sender

3. Turn On, enable Animation and press connect.&#x20;

4. For your ip, if it's the local machine, you can use 127.0.0.1. For port, you can use 9003 or whatever port, but you'll need to remember this for later. <br>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FqRGBuLsPJSgA83dPZZob%2Fimage.png?alt=media&#x26;token=76d99d6f-0a9e-48bb-87e1-8279f8890af3" alt=""><figcaption></figcaption></figure>

5. Create a new layer, and make sure it is the very top layer. This will be a "dummy" layer, do not add color grading or anything else to it. <br>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FozJovLqAi4MQzzWUHs8r%2Fimage.png?alt=media&#x26;token=fc8b1a44-3b34-4d2a-bd74-a8522a38fef6" alt=""><figcaption></figcaption></figure>

## Set up Unreal Engine

You can find the whole blueprint here, copy and paste it into your Level Blueprint, and then connect the Event Begin Play to the Create OSC Server Exec pin. It may have some errors, but you should be able to fix them by following the instructions below.&#x20;

<https://blueprintue.com/blueprint/m6-a4t3l/>

\
Here is another pastebin with a few more things added, that will serve as a template of sorts, for OSC.

<https://blueprintue.com/blueprint/hpe6xzd2/><br>

Manual Instructions for creating the Blueprint.

1. In your Level Blueprint (or you could create a new one), from **Event Begin Play**, add the node **Create OSCServer.** \
   \
   1\. For the IP Address you can use 0.0.0.0. \
   2\. For the Port use 9003 or whatever you set in Live FX\
   3\. Check Start Listening\
   4\. Write the same Server Name you added in Live FX for the Server Name. <br>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FzO2v8KflwEpuRWW8MTDy%2Fimage.png?alt=media&#x26;token=6061140e-71f5-4ff6-95ff-d388e0490e05" alt=""><figcaption></figcaption></figure>

2. Drag off of the Return Value pin and Promote to Variable and (optionally) rename the variable to OSCServer.<br>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2F3YpzbkzJ2dIFN3pIJezD%2Fimage.png?alt=media&#x26;token=9a95f836-03bb-43c2-9064-ab06a449cf50" alt=""><figcaption></figcaption></figure>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FnsNBSA3uFUlBpuu84dCG%2Fimage.png?alt=media&#x26;token=c4103228-1534-4ad9-b0a9-f15f5608f43e" alt=""><figcaption></figcaption></figure>

3. Then add **Unbind All Events from On Osc Bundle Received** and then add **Bind Event to On Osc Message Received**.<br>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FoKi4IiidfWkh3lyUdFzb%2Fimage.png?alt=media&#x26;token=72b6bf27-e0c8-487e-8560-560c7c8d482e" alt=""><figcaption></figcaption></figure>

4. Drag off the Event socket, type **Create Event.** \
   Then in the dropdown select **Create a matching event.**\ <br>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2F3ckEExKlfF7Kv3zFoW40%2Fimage.png?alt=media&#x26;token=32e491b1-0ce5-4de8-872a-357259e7cfa2" alt=""><figcaption></figcaption></figure>

5. **Rename** the event to **OSCMessageReceived** and press **Compile Blueprint.**<br>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FzyvUMT5gpBOW5DSwFuVl%2Fimage.png?alt=media&#x26;token=3798daaa-c75f-48b4-85fa-3cfca87c5964" alt=""><figcaption></figcaption></figure>

6. Drag off the Message pin and promote to a variable. The default name will be Message, we'll keep it the same for now. <br>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FvU145Hp0SbsuuuA9Bemh%2Fimage.png?alt=media&#x26;token=0fe36fb3-0155-42f5-8c00-4937ff050f1b" alt=""><figcaption></figcaption></figure>

7. Drag off that node and Get OSC Message Float at Index, do this three times. \
   For the Index, we'll use 5,6 and 7.&#x20;

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FMO37LSF0nndsr111ureh%2Fimage.png?alt=media&#x26;token=f839fc5b-12f2-4701-9b9c-dc3e95ff32a3" alt=""><figcaption></figcaption></figure>

   :bulb:Remember, the numbers that correspond in Live FX are the following from the top dummy layer:

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2Fh1oGbxcOmZW7hE4LF45d%2Fimage.png?alt=media&#x26;token=ee473732-01ac-43cb-806f-f6b3821ac5ec" alt=""><figcaption></figcaption></figure>

8. From the left-side, drag over the Message Variable and select Get Message. <br>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2F5D91Q2QPkNJe3PDvhRAW%2Fimage.png?alt=media&#x26;token=fab138e6-aa92-4c86-9aec-428f06f82a39" alt=""><figcaption></figcaption></figure>

9. From that variable, connect it to the three Get OSC Message Float At Index. <br>

   <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FWJTlmced8fJGTWRcpRP3%2Fimage.png?alt=media&#x26;token=ee0029ab-4ce8-4013-9202-5e0b7afd89e4" alt=""><figcaption><p><br></p></figcaption></figure>

10. Draf off the execution pin of the last node, **Uncheck Context Sensitive** and search for **Set Relative Rotation**. Choose the **Transformation>Set Relative Rotation.**<br>

    <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2Fm200HHNzTdqTM7mfzFAD%2Fimage.png?alt=media&#x26;token=573cf1c8-8716-4162-8084-89d29b6215fd" alt=""><figcaption></figcaption></figure>

11. Right-click on New Rotation and select **Split Struct Pin**.<br>

    <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FgcINpWzZb8zB2tXtEDiy%2Fimage.png?alt=media&#x26;token=8d2e5617-ba12-43f2-9028-e3c7e8a47daf" alt=""><figcaption></figcaption></figure>

12. Drag the Value from **5 to the Z**, **6 to the Y**, and **7 to the X**. <br>

    <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FXuysRl33TQ4k14XvpLIK%2Fimage.png?alt=media&#x26;token=fab1bdb8-5fd1-414f-919d-08c8a1686fc6" alt=""><figcaption></figcaption></figure>

13. Drag your Directional Light from your scene into the blueprint. Then from the Blue output pin, connect that to the Target of the Set Relative Rotation. This will automatically create a node in between. <br>

    <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2F8c0jwG96uw6i36FPExd2%2Fimage.png?alt=media&#x26;token=20343534-534b-4262-a8c5-343a9fd8db2f" alt=""><figcaption></figcaption></figure>

    <figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2F5Mbl3Rfn3wWLfn4tHcJS%2Fimage.png?alt=media&#x26;token=3327ace6-3124-46be-ab0a-032a795fcb99" alt=""><figcaption></figcaption></figure>

## Control in Live FX

Back in Live FX, to control the X, Y, and Z, you click on the top layer, select the Canvas menu at the bottom left, and then you can use the Rotate X, Y, and Z to control the Sun in Unreal Engine (must be in play mode). <br>

<figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FBOoUa0g5u8CE1dFrBbaf%2Fimage.png?alt=media&#x26;token=a5eff8df-451a-4bd6-8ee4-5c168f14e8b4" alt=""><figcaption></figcaption></figure>

## Custom Blueprints

You can create a blueprint and add many components to it, then you can go to the construction script and do some custom things to have one variable effect multiple components in different ways, in this example, multiplying the intensity variable so that it would be 10x the number that goes to&#x20;

<figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2FedBEoMVZIkxr913JkXYl%2Fimage.png?alt=media&#x26;token=0f6764ec-be77-4533-ab7a-66313b454023" alt=""><figcaption></figcaption></figure>

Here is another example. For headlights in a city scene, we used a blueprint called "00\_BP\_Headlights",  which is a simple actor blueprint with a single Spot Light component.

Inside of each vehicle blueprint, we brought in this blueprint twice, these two act like the headlights.&#x20;

In the Level blueprint, we Get OSC Message Float At Index, then Get All Actors Of Class. We select the class 00\_BP\_Headlights, then add a For Each Loop, and set the intensity to the Value set in the OSC message.

<figure><img src="https://4002977754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrQtfp6C58EggcONhzAMx%2Fuploads%2F3XFpXfC6nebEbZ4APSvn%2Fimage.png?alt=media&#x26;token=829f38c4-b3d4-4bc7-ada7-a7a06a617954" alt=""><figcaption></figcaption></figure>
