Actions — how to write them

Al Heck
Dec 3, 2021

Actions are the same as delegates and events combined — makes the actual writing far simpler.

Let’s pretend I wanted to create a damage system but I wanted my UI manager to subscribe to the event changes on my health system. If I want an action to occur, I need to access the System library and implement the action this way depending on if it passes in a parameter or now.

Now let’s create a typical damage system.

Now let’s call an Action after health so our UI manager knows to update the health count. We want to use 2 since we are passing in a parameter.

Now on our UI manager, we created an update health script that shows the current health. Whenever the player takes damage, the UI manager will be notified of the event and pull the latest value.

--

--

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ