+20

Custom Units: Basics Part 1: Input Output (+ isControlRoot and Relations)

JasonJonesLASM 2 years ago updated 1 year ago 7

*Removed*

Thank you for everyone who enjoyed my tutorials. It was obviously becoming very out of date. I am now, with my company website, releasing new tutorials to replace all of these here. I'm taking the liberty to release both 2.x and 1.x tutorials at the same time, until 2.0 is officially prime and ready.

http://lifeandstylemedia.com/tutorials.php

I will be releasing a new tutorial every day this week (7/1/2019).

July 1 )  Custom Unit Basics : Part 1 - On Enter Value Manipulation

July 2 ) Custom Unit Basics : Part 2 - Coroutine Ports - The Type Writer Effect

July 3 ) Custom Unit Basics : Part 3 - Error Handling

July 4 ) Common Attributes

July 5 ) Inspectable Types (Includes Editor Code)

You can also look for me to do my runtime logic tutorials that do not require any C#. Just Visual Scripting.

Enjoy!

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

Thanks for the tutorial. Waiting for next tutorials to get hands more dirty, but this already lowers the barrier to start experimenting more and more.

+3

Right on, this was actually quite relaxing to do. Might just do it tonight or tomorrow! I'll begin touching on multi count ports, which coincidentally will allow me to start talking about headers, and using attributes for things like placement in fuzzy finder, hiding port labels, ect.  

I'm debating pushing up the site release too, without all the new custom units right off the bat, to get all of this going. 

+4

The code above will throw an assertion for anyone trying to use this in 1.4.

The input/output has changed. I have quick fix below. 

public class InOutUnit : Unit
{

    [DoNotSerialize]
    public ControlInput input { get; private set; }
    [DoNotSerialize]
    public ControlOutput output { get; private set; }
    [DoNotSerialize]
    public ValueInput valueIn { get; private set; }
    [DoNotSerialize]
    public ValueOutput valueOut { get; private set; }

    protected override void Definition()
    {

        input = ControlInput("in", Enter);
        output = ControlOutput("output");

        valueIn = ValueInput<float>("valueIn");
        valueOut = ValueOutput<float>("valueOut", ReturnFloat);

        Requirement(valueIn, valueOut);
    }


    public ControlOutput Enter(Flow flow)
    {
        return output;
    }

    public float ReturnFloat(Flow flow)
    {
        return flow.GetValue<float>(valueIn);    
    }


}



+2

Excellent, thank you for helping. A little behind on the API for 1.4 right now.

+2

No problem. I had a lot of custom units screaming so I had to fix it. I figured this will help those upgrading to 1.4 with custom units

Any idea how one would get the valueIn value in Definition()? There is no flow available at that point. I'm rebuilding GlobalEventUnit events and cannot find any way to get the object in the ValueInput in order to subscribe to events. As for the rest of the changes, I figured out how to use EventBus to actually trigger the Bolt event.

Excellent, works perfectly with the 1.4