Time for action – Using function parameters
Time to pass some variables around! Let's start with the PostBeginPlay
function in our AwesomeEnemySpawner
class.
We haven't defined the
PostBeginPlay
function for ourAwesomeEnemySpawner
class, so let's do it now, and let's add anint
to the function parameters:function PostBeginPlay(int MyInt) { }
Compile the code. Uh oh, an error right out of the gate:
Error, Redefinition of 'function PostBeginPlay' differs from original; different number of parameters
This is the most important thing to remember about function parameters. Once a function is defined, if it's ever used in a subclass, then it must have the exact same number and type of parameters as the original. The names of the variables don't have to be the same, but if the original function has a
bool
and anint
, any subclasses must have abool
and anint
in their parameters.Let's take a look at an example of this. We've been using the
Tick
function a lot. If we look inActor.uc
where it's declared...