Unity Integration Guide
This is how you integrate Machinations UP into your Unity production
Last updated
This is how you integrate Machinations UP into your Unity production
Last updated
Even though our integration has reached Open Beta maturity, this section will see some changes in the future.
At this point, you've probably been through our tutorial and/or have UP operational in your project.
The simplest way to use Machinations UP is to integrate it into your game's Scriptable Objects. This is one of the common ways Unity handles game-related data.
Let's jump right into it, and deal with additional details later. For now, you shouldn't look too deeply into anything, just take this as a quick tour. You'll be up in running in minutes.
You can either create a new Scriptable Object or, why not, extend one of your current ones by infusing it with some MachiMagic :). Whatever the case, you need to either create or pick an int value in your ScriptableObject.
Being an abstraction & design tool, Machinations only works with integers. If you need floats, send a larger integer from Machinations and divide it as necessary. For example, if you measure speed on a scale of 0.0 to 10.0, just use 100 from Machinations and divide by 10
It's possible that your game will begin playing before new Machinations data arrives from the server. You may not like that. For this reason, UP can interact with your game engine via the IGameLifecycleProvider interface.
In the UP package, check the class SampleSceneStartupHandler. If you uncomment the RuntimeInitializeOnLoadMethod attribute, this class will instantiate our crudest implementation of an IGameLifecycleProvider.
The SampleGameEngine we provide will simply pause/unpause the game by tampering with Time.timeScale. The MDL will request unpausing the game when it completes its first request at game startup.
More complex behaviors can be achieved by using the MDL.Prepare() method, which will let you schedule your Machinations initialization as you see fit. This method will also notify your game engine of the ongoing initialization.
As you prepare to run your game and see the results of your changes, now would be a good time to also check that UP's internal logging works. Open the class MnEntryPoint. This is the class that controls Machinations behavior during your editor/game session.
The first line in the InitMachinations function is:
Change it to Debug.
Upon starting your game, you should see some debug messages in the console. Search for "Game Auth Request" and if you correctly set up your User Key & Diagram Token, you should see a "Success" there.
You can also search for "MDL" to see what the Machinations Data Layer has been up to.
We will have more integration examples & use cases in the near future.
If you're curious to read more about the classes involved, please check the .
As a reminder, here's a start-to-finish Scriptable Objects integration (the same from our tutorial). It covers all the above steps.