Switch to meele

Rather basic modding question: how can I make ranged cavalry automatically switch to meele mode when engaged in hand-to-hand combat, just like infantry?
Many thanks.

You can give attacks a minimum range
That should make the unit switch to meele when to close.

I think that’s not enough.

Just added
to the unit ranged protoaction, but the unit now pulls back to use their ranged attack.

I had to change the unit respective tactics file, allowing the MeleeHandAttack as an available action in each stance

Thanks gentlemen and sorry for the late answer.
Editing the units’ tactics file is probably a bit too much for me, since my greatest accomplishment in modding my version of the game was changing some names and stats.
If somebody has already tried that, could you maybe paste some significant strings so that I can blatantly copy the proceedings?