⚙ Unity Plugin (UP) & API

    Documentation

    Unity Integration Guide

    Unity Integration Guide

    warning

    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 Quick Start 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.

    success

    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

    1. If you created the value, give it the type ElementBase. If you are modifying an int value you already had in your ScriptableObject, just change its type to ElementBase. Let’s say you’re adding/modifying a Movement Speed value:
    1. You need to implement the IMnScriptableObject interface. Our MnDataLayer (lovingly called the MDL henceforth) will call methods in this interface throughout your development session, both when the game is running and when it is not (this will be configurable in the future).
    1. To define how you will connect your value to Machinations, you will declare a MnObjectManifest and enroll it with the MDL. You must do this in the OnEnable function of your Scriptable Object:
    1. Now, let’s implement the IMnScriptableObject interface. That’s going to be way easier than you’d think, and the code is pretty self-explanatory.
    1. And that’s it. Congratulations. You now have a value that pulls its data from Machinations. Now go and put that to good use! 🙂

    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.

    If you’re curious to read more about the classes involved, please check the UP developer documentation.

    info

    It’s important to understand we’ve built UP to be a versatile solution. There are multiple ways to obtain the same result, depending on what features you’d like to use. We are here to offer some best practices (and, with your feedback, to perfect those best practices).

    We will have more integration examples & use cases in the near future.‌

    As a reminder, here’s a start-to-finish Scriptable Objects integration (the same from our Quick Start tutorial). It covers all the above steps.

    Contents

    Used by 2500+ game studios all over the world

    350+ universities & academic institutions use Machinations

    All Rights Reserved © Machinations S.àr.l

    8217, Mamer, Luxembourg, accounts at BGL BNP PARIBAS, VAT number: LU30464284

    We use cookies for marketing and analytics. We also share information about your use of our site with our marketing and analytics partners who may combine it with other information that you’ve provided to them. You consent to our cookies if you continue to use our site. Learn more