Unreal Engine
Last updated
Last updated
The Unreal Engine is a powerful tool to create complex and visually stunning physics based experiences. The Magic plugin for the Unreal Engine makes it simple to bring in and extend the physical world into Unreal whether for more intuitive interfaces with virtual production, real time data driven simulations, or video games that truly leap out of the screen. The Magic plugin presents everything through Unreal’s Blueprint interfaces for fast visual programming.
There are two different Magic plugins for the Unreal Engine depending on if you are building and running your experience on Windows or Mac. This is due to the underlying code Unreal is built on top of for each platform. We handle everything under the hood for you, so you just have to make this decision here. Click on the link below for the platform you are developing with to download the proper plugin:
Create a new Unreal Project with C++ enabled vs Blueprint. For this example we will use a “Blank” project without any starter content. After the project initializes close the project.
Open your project’s folder. Create a new folder titled Plugins.
Uncompress and drag the folder you downloaded into the Plugins folder. The plugin is labeled Nexus.
Open your project again from the Epic Games Launcher. You will receive a prompt asking if you would like to rebuild the modules. Click yes.
For this example we will stream data through the Level Blueprint. To open, click on the Blueprint dropdown menu and click Open Level Blueprint.
Any time that you will be streaming data, you must make sure to include the Stream - Connect node and Stream - Disconnect node in your Level Blueprint. These will be tied to EventBeginPlay and EventEndPlay respectively. To add both, right click and search for Stream - Connect and Stream - Disconnect. If you search Nexus this will also show you all of the plugin’s nodes. If EventEndPlay is not in your Blueprint, right click and search for it. Connect the nodes so that your Level Blueprint looks like the image below:
The Stream - Connect node has a Port Number input and Wireless input. On Windows, enter the COM port it is connected to. On Mac, you can leave this as 0. If you want to connect wirelessly on Mac, check the wireless checkbox. On Windows the COM port will override and handle the wireless connection. For more information and the proper drivers for connecting a piece of hardware on Windows see here and on Mac see here.
To stream data from input module’s into Unreal you need to add the Stream node to the Level Blueprint. The Stream node needs to be driven by an event. This can either be the Event Tick or a Custom Event. We suggest a Custom Event since intensive operations on the Event Tick will impact your experience’s frame rate. Our Custom Event will be driven by a timer. Events can also be triggered by occurrences in game, if for example you only want data at a specific instance.
To add a Custom Event, right click and search for Custom Event. You can rename it to whatever you would like, in the example we have called ours StreamEvent. To add the timer that will drive the event, right click again and search for the Set Timer By Event node. Connect the Custom Event red output to the red Event input on the Set Timer By Event Node. On the Time input on the Set Timer By Event node, enter .125. This time can be any value of your choosing but we have found that .125 is a good balance between frame rate and input speed. Check the Looping input checkbox.
Right click and search for the Stream node. Connect the output of the Custom Event node to the input of the Stream node. To kick off the timer, drag the output of the Stream - Connect node to the Set Timer By Event node. Your Blueprint should look like the image below:
To access data from any input module, right click and search for it by name. Connect the Input Module node’s input to the Stream node’s output. All Input Module nodes have both their 0-100 mapped properties and raw data values as outputs. For this example we are using a Proximity Module and printing out its mapped amount to the screen. Add a Print String node to the Blueprint and drag the amount output to the In String input. Unreal will create an intermediate node to convert the number to a string. Your Blueprint should look similar to the following:
Make sure to compile and save the Level Blueprint. Now once we click play you will see the proximity amount (or the data from whichever input module you using) printing to the screen!
To add an output module to a Blueprint, right click and search for Stream - Output. This node will be your main node for sending data to output modules. To add an output module, right click and search for it by name. In this example we are using a Glow Module. Drag the output output of the Module node into the Value input of the Stream - Output node. To send data, an event must trigger it. In this example we are using the G Key keyboard event to trigger the output. Right click and search for keyboard and scroll down until you reach the G Key. Drag the pressed output of the G Key Event node to the input of the Glow Module, and connect the output of the Glow Module to the input of the Stream - Output node. Your Blueprint should look like the image below:
You have to set the data for the output module. This can be either dynamic and driven from in game or fixed. If it is dynamic, drag a value from a node into the input of the Output Module node. In this example with the glow module it will be fixed. To set a color on the glow module, click on the black square on the color input. This will open a color picker. Choose the color you would like and click ok.
Make sure to compile and save the Level Blueprint. Now once we click play and press the G Key your glow module will light up to the chosen color!