Skeletons made in blender reset bone rotations to 0 when enabling IK, causing broken limbs

https://i.imgur.com/YWlVplF.png This is how I think UE4 wants me to rig my model, with the leg control parented by the root bone.

https://i.imgur.com/lvowUJn.png This is what that results in.

https://i.imgur.com/38eggs8.png This is my preferred rig setup.

https://i.imgur.com/n8NWh4q.png This is the result of that.

As you can see, the model seems to roll the foot 180 degrees so that the bottom of the foot is facing up rather than down. When I follow the exact same steps in the Third Person demo I get the results I’d expect, with the foot being planted on the ground. I can mess around with the location of the IK bone and the proper bones move but they move within the context of this warped foot bone. Has anyone else experienced this problem? I tried to look up specific blender to unreal tutorials and everyone seems to have a rig similar to my own.

I’ve also found this thread which looks similar to my issue: IK foot rotation out of whack - Character & Animation - Unreal Engine Forums

But there are no answers. I’ve tried all of the obvious troubleshooting options like changing the foot bone forward axis and enabling rotation limits etc. I have a feeling that this has something to do with how I rigged my character but I’m not sure. Has anyone had this issue before?

And the IKFoot Bone is normally set to the IK bone on the model. The reason it’s set to leg control in those images is because of me trying to see if a different bone would solve the issue. It didn’t.

I’ve imported the mannequin into blender and then reimported it back to UE4 and the issue doesn’t happen there. Everything works as expected. Even if I make a rig with identical hierarchy to the UE4 one this problem occurs.

https://i.imgur.com/dnnxITx.png Even with a basic rig this problem happens. This is what it looks like with leg IK on.

https://i.imgur.com/1LcyEuK.png This is with leg IK off.

So as an update to this, using some settings another user told me about I was able to import the mannequin in the way I’d expect with the bones aligned the way they are when I make skeletons myself: https://i.imgur.com/rcvgWoD.png

I then put this model back into UE4 and the same issue started happening when I turned on leg IK: https://i.imgur.com/tQsrzsl.jpg

So this has to be something to do with the rotation of the bones before they go into the engine, right?

UPDATE 2: The rotation of these bones after enabling IK seems to be the same rotation of the bones when they’re zeroed out. So if I go into the skeleton and set the local rotation of a bone to 0, 0, 0, it will be in the same position as it is when I enable leg IK. So I will somehow need to find a way to set the rotations of all the bones in their rest position to 0 if I’m going to use the IK system.