That way, you can access it inside Update. Though if you need the gameobject, not the collision event itself, it’d best be to save the gameobject, not the collision.
Oh wait, I made an error, the “Collider2D collider;” needs to be outside the method, not inside. Just in case you didn’t figure that out yourself.
@Neomedus Glad you are operational. This might be obvious too, but one handy thing I like to do with this pattern is in Update() when I notice that the collision has been set and take action, it’s handy to also set it back to null, to signal that the Update function has basically “consumed” the event.