You need to use a unit variable to do this. After the unit is created (I assume a trigger creates it) you can add another function that is 'set variable = last created unit'.
To make the variable, go onto the variable section of the trigger editor, create a new variable, and make it a unit...