Pure Functions

Chris Didier
2 min readMay 23, 2022

We are going to be learning how to remove execution pins from our own functions and how and when it’s a good idea to do this.

What is a side effect

When a function has an observable effect after it has been run.

Examples

  • Print String
  • Add Impulse
  • Set Ammo

What is a Pure Function?

  • A function with no side effects
  • Only Return Values
  • Ex
  • --Get Ammo
  • — Get Actor Forward Vector
  • — Multiply, Minus, Greater…

On our test function if we select the pure option in the details panel all of our execution pins disappear.

Before

After

Now this function will run whenever we need the output. If we were to put this before the print string the result would be printed.

We are going to make our HasAmmo function a pure function. When we do this all we have is our bool that connects to our branch.

Our function still works the same. When we run out of ammo we can no longer fire.

A good indicator is our function a verb or ask a question as to what type of function we have.

Now we know what to look for in the future.

--

--