Issue With IK Rig UE5

Hello,

I’m trying to use the control rig on a character. The issue I’m having is that when I setup the IK rig for the leg it twists and turns the leg in odd ways. I have tried making sure the primary and secondary axis is orientated to the skeletal mesh but I can’t seem to solve the issue. I have included some photos of the issue. Any help would be greatly appreciated.

The skeletal mesh

The setup

The bad orientation

The correct orientation