I made a ray traces in UE4 and I used both custom nodes, shader code that I added to the loaded shader files in the engine, and recursive functions in the material editor. I am unable to see why using functions in a shader is not doable. If you are thinking of calling a CPU function from a shader, then that is not possible. The closest thing would be a GPGPU style issue where the result determines the next action on the cpu.
You can implement a raymarcher using UE4, I did it.