Skip to content

6. Actions

Knowlife4 edited this page Mar 10, 2023 · 1 revision

Actions help keep clutter down by allowing proper separation between systems. If you are familiar with C# delegates or actions, you will likely be familiar here as well.

Actions can have methods subscribed to them, when the action is executed, all of the subscribed methods are executed.

Note: Actions currently only support methods with 0 parameters.

Creating an Action

Creating an action is incredibly easy, all you need to do is create a public ECTAction field within your system.

Ex. public ECTAction OnLand

Subscribing to an Action

It is recommended you create a brand-new method for each action you are subscribing to.

To subscribe to an action, execute the Subscribe method on the action using the method you want to subscribe as the parameter.

OnLand.Subscribe(OnLand)

Note: A method can only subscribe to an action once, allowing you to subscribe to an action in an OnUpdate().

Executing an Action

To execute an action, call Execute() on it and all subscribed methods will be executed.