Game Toolkit for Unity
Machines are what drives your game – learn the basics about those components!
A machine is a Unity component that plays a Schematic – in short, a schematic is a blueprint for what you want to do, and a machine makes it happen. You can learn more about schematics in this how-to.
There are different machine components available for different use cases. Each machine component has it’s own documentation with more details, so let’s just get a brief overview.
Beside machine components, there are Global Machines that can be used everywhere and anytime. You can learn more about global machines here.
The machine component’s Machine Execution Settings defines the schematic the machine will use. Starting a schematic requires a schematic asset.
Additional settings further specify the machine’s execution, which influence the impact/effect of the schematic’s execution individually and in context to other machines.
The machine’s Execution Type defines how a machine is executed:
The Update Type defines in which Unity update function the machine will be updated:
You can optionally prioritize a machine, this will update a machine before other machines. When multiple machines are prioritized, they’re order descending by their Priority number, i.e. the machine with the highest priority number will be updated first.
However, prioritized machines will start playing the schematic in the next frame, not in the frame they’re started (as not prioritized machines do). This is due to waiting for all prioritized machines that are started in a frame and ordering them according to their Priority number. I.e. a priority machine ensures starting before other priority machines with a lower priority.
E.g. 3 auto machines start when a scene is loaded:
The machines will start playing the schematics in the following order:
There are additional settings that can be left alone in most cases.
The machine type is mainly used by Interaction type HUDs to e.g. show different HUDs for different machine types.
Machine types are created in Base/Control > Machine Types in the Makinom editor.
If enabled, the machine’s schematic will be stopped when the machine’s game object is destroyed.
This setting handles what will happen with the machine’s game object after the machine finished executing the schematic.
Beside doing nothing, you can disable or destroy the game object.
You can optionally use wait times before starting the schematic’s execution and before ending the machine’s execution state.
You can optionally have the player face the machine and the machine face the player.
You can optionally automatically stop the schematic’s execution when the machine’s conditions are no longer valid.
The machine can optionally use a defined input ID instead of the game’s current input ID.
Input IDs are used by input keys to allow different input origins, e.g. for local multiplayer controls or control styles.
Game Object type actors added to the machine’s schematic can be selected in the machine’s settings. That’s the way to go in case you want to use a specific game object in your scene.
The Actors settings are only displayed if a Game Object type actor has been added to the schematic.
Assets added to the machine’s schematic can be overridden by the machine. This further increases the reusability of schematics, as you can create more generic schematics that perform a task, but use different assets on different occasions.
The Resource Override settings are only displayed if resources like prefabs, audio clips or sprites are added to the schematic in it’s Settings node.
Overriding the prefab resource in a Tagged Machine used to animate the death of enemies allows having particle effects, e.g. a plant enemy spawning leafs while a human enemy spawns blood.
If a machine is started is depending on the selected start type (there are different start types available in the different machine components, e.g. a trigger machine can start upon Trigger Enter, Trigger Stay and Trigger Exit) and optional conditions that will be checked. While some machine components have additional conditions that can be checked, the following conditions are available for most machines.
After adding conditions you’ll have the Auto Check setting available, which defines when the conditions are checked.
A machine can be started depending on the position of the machine and the starting object. You can check if the starting object is in front, back, left or right of the machine. E.g. you can make an interaction machine (e.g. opening a door) only able to start when the player is in front of the door.
This condition is not available for animation state machines.
Starting a machine can depend for the game to be in defined states. The game can have multiple active game states at the same time – states can be changed automatically upon certain events (e.g. blocking the player control) and through schematics. You can learn more about game states here.
An interaction machine (e.g. displaying a dialogue) is only able to start while the game state In Control is active, which is set to only be active while the player can be controlled. This way, the interaction will only be available while the player is in control, i.e. it can’t be started during blocked control (e.g. in a cut-scene).
Starting a machine can depend on variables having certain values – variables and variable conditions allow creating advanced and complex game mechanics. You can learn more about variables here
A trigger machine (e.g. starting a cut-scene or auto saving the game upon entering the trigger) is only able to start when the bool variable quest_A_started is enabled. The variable is enabled by another schematic, e.g. through a dialogue with an NPC.
A machine can initialize the local variables of the schematic it starts to defined values. While you can also set them in the schematic, setting them in the machine allows reusing the schematic with different start variables, doing different things or behaving differently.
An auto machine creating a tiled level with a random layout gets the level’s size from the local variables. Using two int variables (e.g. columns and rows) to define the size, you can create different level sizes with the same schematic. Level 1 can have a size of 8×8, level 2 a size of 10×8, etc.
A trigger machine will damage the player (reduce the health variable of the player) when he enters the trigger. Using an int variable (e.g. damage) to define the damage that will be done will allow using the scame chematic to do different damage on different machines.
Schematics can also define Machine Start Variables, local variables that will be exposed to machines for quick setup. The machine start variables of the schematic will also be listed here.
Machines can automatically change variables after they finished execution. While you can also change variables in schematics, doing this in the machine allows reusing the schematic for different purposes and changing different variables.
A trigger machine will add points to the player’s score (e.g. increase an int variable score) when he enters the trigger. To only get the points once, change the bool variable points_A_collected after execution to true and use a variable condition checking for that variable to be false. Using a different variable for each points collection will make them unique and only be collectible once. Changing the variable in the schematic would change the same variable for all machines, requiring to have different schematics for every individual points collection.
A tagged machine will remove (kill) an enemy game object, playing an animation and an audio clip. The resource overrides allow reusing the schematic for different enemies and using different audio clips. To add a kill counter for different enemies (i.e. keep track of how many enemies of different types you’ve killed), increase different int variables for different enemies (e.g. enemy type A increases enemy_A_counter, enemy type B increases enemy_B_counter).
© 2015 Gaming is Love e.U.
Disclosure: This site may contain affiliate links, which means I may receive a commission if you click a link and purchase something that I have recommended. While clicking these links won’t cost you any money, they will help me fund my development projects while recommending great assets!