Automatron

An automation tool for Unity 3D

  1. Frequently Asked Questions
  2. Examples
  3. Controls
  4. How To
  5. Settings
  6. Custom Automation
  7. Custom Conditional Automation
  8. Custom Loopable Automation
  9. Generator
  10. Automation List
  11. Automation Reference

Frequently Asked Questions

Where can I get it?

Right over here!

I have an issue/request, where can I voice this?

Please go here and create an issue, thanks!

I have a tip/question, where do I go?

Please send me an email and I’ll see what I can do!

Do you have other stuff?

Yes I do! You can check out my github!


Examples




Controls

Automatron Window

Left Mouse Button
Select field
Make connection lines

Middle Mouse Button
Pan

Right Mouse Button
Open Add Automation popup

Spacebar + Left Mouse Button
Pan

Spacebar + Right Mouse Button
Pan

Automation

Left Mouse Button
Drag

Right Mouse Button
Open context menu


How To

Create An Automatron

main page

Whenever you want to create a new Automatron you have to click the Create button in the top-right corner. This will bring you to the create page.

create page

Here you can choose the name and path for your Automatron. The path defaults to the Config Folder in the Preferences but you can change it for a single Automatron. By clicking the three dots, a folder picker will appear to help you fill in a custom path.

create page duplicate

If an Automatron already exists, it will show you the following message under the Name box. Clicking create will overwrite the already existing one without any extra warning, so be careful.

Open An Automatron

main page

Whenever you want to open an existing Automatron you can simply click on one from the list shown on the main page. If the Automatron you want to open is not in the list you can click the Open button in the top-right corner, this will open a file picker to select a config file, whenever you open an Automatron like this it will be added to your recents list.

missing reference

It can happen that files go missing. Whenever you click on an item in the list that no longer exists or has been moved the editor will ask you if you want to remove the entry from the list. Note that this list is shared over all instances of this tool so beware of relative config paths.

Add New Automations

You can add a new Automation by clicking either the Automations button in the toolbar or clicking the right mouse button.

Add Automation popup

You can use the search bar up top to look for Automations by name, or scroll through the list manually. Items with an arrow pointing to the right are group items with children.

Simply click on the item you wish to add to have it added to your Automatron.

Remove Automations

You’ve made a mistake and added the wrong Automation. Don’t worry. You can simply click the cross button in the top right of every Automation to remove it again. If there were any lines connected to it then these will also be removed.

You can also click the trash icon in the menu bar. Clicking this will remove everything but the Entry Point, so you’ll be with a clean Automatron again. You’ll get a popup to confirm your action.

Take the following example:

Linked

First we find all the GameObjects with the tag “Custom Obj”, then we loop through all of those found and set the Is Static field to true.

We define the order of the Automations by drawing lines from Automation to Automation. You can connect them by clicking on the arrows sticking out of the top or bottom.

Sometimes you want to share values between Automations. This can be done by linking the fields with lines. This is almost the same as connecting Automations, the difference is that you have to click on the block sticking out on the sides of the fields.

Note: the arrows on the top are the normal way of defining what comes next. The arrows at the bottom are special arrows that are used for loops or conditionals.

To unlink Automations or fields you can right click the arrow or block where a line is connected to unhook all of the lines that are connected to that arrow or block.

To unlink all incoming our outgoing lines you can also right-click on the “toolbar” of every Automation. This will show a popup menu giving you the two options.

remove lines

Create Custom Automation(s)

There are three types of Automations that you can make:

For regular Automations see Custom Automation
For Conditional Automations see Custom Conditional Automation
For Loopable Automations see Custom Loopable Automation

If you want Automations to be generated, based on one or more types, see Generator


Settings

The settings for Automatron can be found in the Unity Preferences window and should look a bit like this
(Edit->Preferences…->Automatron)

settings

Automations Folder
The folder where the newly created Automations will be placed
Default value: Assets/Automatron/Editor

Config Folder
The folder to store newly created configs
Default value: Assets/Automatron/Configs

Auto Save
Should it auto save your Automatron
Default value: true

Automation Line Color
THe color used for the lines that connect Automations
Default value: White

Field Line Color
The color used for the lines that connect fields
Default value: White

Focus Active Automation
Should the editor center on the currently active Automation (while executing)
Default value: true

Focus New Automation
Should the editor center on a newly added Automation
Default value: true

Animation Utility.Constrain To Polynomial Curve

Summary

-


Fields

Type Name Extras Summary
AnimationCurve curve - -

Method Body

public override IEnumerator Execute() {
	UnityEditor.AnimationUtility.ConstrainToPolynomialCurve(curve);
	yield break;
}

Custom Automation

Let’s say that the Automations that come with the tool don’t quite hit the spot for you, they are to generic, too specific. They just don’t fit your needs. Luckily you can make one yourself!

Click File->Create…->Automation and fill in a nice name for your Automation and click OK. This will create a file with the bare minimum required for an Automation in the Automations folder.

Adding ‘/’ (without quotes) will add subfolders to the Add Automation popup.

create menu

create popup

Browse to your newly created Automation and open it (default: Automatron Folder/Automations) and you should see something like this.

#if UNITY_EDITOR
using System;
using System.Collections;
using TNRD.Automatron;
using UnityEngine;
using UnityEditor;

[Automation( "My Automation" )]
public class MyAutomation : Automation {

    public override IEnumerator Execute() {
        throw new NotImplementedException();
    }
}
#endif

The [Automation( “My Automation” )] attribute specifies that this class is an Automation that can be used in the tool. The text in quotes is the path that will be used in the Add Automation popup.

The public override IEnumerator Execute() method is the method that will be executed whenever the Automatron is in execute mode. Note that the return type is IEnumerator; This allows you to use this method as a coroutine so you don’t block the whole thread if you’re doing something in a loop.

Here’s an example of an Automation that waits for a certain amount of time before continuing.

delay automation

[Automation( "Delay" )]
public class DelayAutomation : Automation {
    // The amount of seconds to delay
    public float seconds;
    // The start time of this Automation
    private float start;

    public override void PreExecute() {
        start = Time.realtimeSinceStartup;
    }

    public override IEnumerator Execute() {
        while ( Time.realtimeSinceStartup < start + seconds ) {
            Progress = 1f - ( ( start + seconds ) - Time.realtimeSinceStartup ) / seconds;
            yield return null;
        }

        yield break;
    }
}

As you can see the public fields (and properties) are automatically shown in the editor. The private fields and properties are not, these are just for you.

PreExecute
This automation is kind of a special case. Right before it executes it needs to set the start time, and it needs to do this every time it executes. This is where the PreExecute method comes in. This method is executed right before the Execute method, it is basically a sort of initialization call. I would suggest you don’t put heavy code in here for the sake of speed.

Progress
Another thing this Automation does is update progress. Every automation can do this, but will be automatically set to 100% (aka 1) whenever it is done executing, so if you forget to set your progress, don’t worry. This is useful for Automations that take time, maybe because you are looping through a collection or maybe another reason. I’d recommend showing progress for slow Automations.


Custom Conditional Automation

Click File->Create…->Conditional Automation and fill in a nice name for your Automation and click OK. This will create a file with the bare minimum required for a Conditional Automation in the Automations folder.

Adding ‘/’ (without quotes) will add subfolders to the Add Automation popup.

create menu

create popup

Browse to your newly created Automation and open it (default: Automatron Folder/Automations) and you should see something like this.

#if UNITY_EDITOR
using System;
using System.Collections;
using TNRD.Automatron;
using TNRD.Automatron.Automations;
using UnityEngine;
using UnityEditor;

[Automation( "My Conditional" )]
public class MyConditionalAutomation : ConditionalAutomation {

    public override IEnumerator Execute() {
        throw new NotImplementedException();
    }

    public override bool GetConditionalResult() {
        throw new NotImplementedException();
    }
}
#endif

This type of Automation is almost the same as a normal one, except for one thing. The GetConditionalResult() method.

This method is what determines what Automation should be the next in line. If the result is true, the next Automation will be the one that is connected to the arrow on the right. If the result is false, the next Automation will be the one that is connected to the arrow on the bottom.

Here’s an example of a Conditional Automation that checks if a value is greater than another.

delay automation

[Automation( "Greater Than" )]
class ConditionalGreaterThan : ConditionalAutomation {

    public int A;
    public int B;
    public bool Result;

    public override IEnumerator Execute() {
        Result = A > B;
        yield break;
    }

    public override bool GetConditionalResult() {
        return Result;
    }
}

Custom Loopable Automation

Click File->Create…->Loopable Automation and fill in a nice name for your Automation and click OK. This will create a file with the bare minimum required (and maybe a bit more) for a Loopable Automation in the Automations folder.

Adding ‘/’ (without quotes) will add subfolders to the Add Automation popup.

create menu

create popup

Browse to your newly created Automation and open it (default: Automatron Folder/Automations) and you should see something like this.

#if UNITY_EDITOR
using System;
using System.Collections;
using TNRD.Automatron;
using TNRD.Automatron.Automations;
using UnityEngine;
using UnityEditor;

[Automation( "My Loopable" )]
public class MyLoopableAutomation : LoopableAutomation {

    private int index = 0;

    public override void PreExecute() {
        index = 0;
    }

    public override IEnumerator Execute() {
        throw new NotImplementedException();
    }

    public override bool IsDone() {
        // return index == ?
        throw new NotImplementedException();
    }

    public override void MoveNext() {
        // index++
        throw new NotImplementedException();
    }
}
#endif

The public override bool IsDone() method is the method that is used for checking if the loop has been finished.

The public override void MoveNext() method is the method that will be executed after the loop cycle has been executed. This means all the Automations that are connected to the bottom arrow have run and.

The commented lines are there to give you a quick tip of what you can do.

Here’s an example of a Loopable Automation that does a for each loop.

delay automation

[Automation( "For Each" )]
class ForEachLoop : LoopableAutomation {

    public Array Collection;
    public object Value;

    private int index = 0;

    public override void PreExecute() {
        index = 0;
    }

    public override IEnumerator Execute() {
        if ( Collection.Length == 0 ) {
            Progress = 1;
            yield break;
        }

        if ( index < Collection.Length ) {
            Value = Collection.GetValue( index );
        }

        Progress = (float)index / Collection.Length;

        yield break;
    }

    public override bool IsDone() {
        return index == Collection.Length;
    }

    public override void MoveNext() {
        index++;
    }
}

Generator

Let’s say you have a custom class which you want to be able to use in Automatron but you don’t feel like writing all those Automations yourself. Or maybe there’s a type in Unity that didn’t come with all the right Automations. For those situations you can use the Generator, which will save you a lot of time.

create menu

The Generator is located at File->Create…->Generator

generator

Libraries

Assembly-CSharp
This is the library that holds your project’s code. If you create a custom MonoBehaviour or something alike, it will be in here.

Assembly-CSharp-Editor
This is the library that holds the project’s editor code. All code that resides in an Editor folder will be in here.

mscorlib
This is the library that hold most of the (if not all) system types.

UnityEditor
The UnityEditor library used by your current Unity version

UnityEngine
The UnityEngine library used by your current Unity version

Base Type

The base type section allows you to limit the list to types that derive from the type selected. For instance UnityEngine.Component for all the components.

Search

You can also limit the list of types that start with the text from the search bar.

Types

This is where the (filtered) types are. You can check/uncheck them by clicking on the checkbox in front of every name.

wizard

Whenever you have selected the types that you want, you can click generate to pop up the wizard. The wizard will show you the fields, properties, and methods this type has. Both static and non-static.

The toggle buttons will invert the checkbox values so you can easily select all of them (or none).

If you have more than one type selected you can use the bottom arrow buttons to switch between types.

Whenever you’re ready you can hit the Generate button. This will take the selected values and turn this into Automations. Please note that some types (like lists) are not supported properly, and will show weird values. You might also have to go in and edit some of the files because of compile errors though this should be minimal.

Side note: You can export methods with the same name but with different parameters but only one will appear in the Add Automation popup, if you want them all you have to manually rename them.