How to create a small freeze / delay when certain actions happens between 2 objects?

I have 2 objects in a platformer, the player and the enemy.
I want when they collide or attack and hit eachother, they for a brief moment freeze.
For example when they collide, the player gets a bit of force in the opposite direction that pushes him back. But before this happens I want a split second the player and enemy stop moving/jumping/attacking/falling whatever… What is the best way to approach this?

I would say the best approach is to use a small state machine. That way if they are in any state (moving/jumping/attacking/etc.) and they collide, you can switch to a Freeze state before using a Knockback. In the freeze state you will want to stop all movement/velocity, or if they are falling then you may want to temporarily stop gravity on the rigidbody2d. Then, you would determine which direction they collided and knock them back after X seconds in the direction opposite of the collision.

A state machine might be overkill but its really clean, very useful, and easy to build upon.

ok, I’ll look into that. Thanks for your advice