DistanceFieldGradient and DistanceToNearestSurface won't work right

I am trying to get a similar effect to the ones shown in the example materials listed at:

and:

Utility Material Expressions in Unreal Engine | Unreal Engine 5.1 Documentation.

However, even though I reproduced the materials exactly, I am not getting anywhere near the desired result. Instead, all I get is a solid red object. I get the same result for both materials. (Here are screen shots of the materials and result)

Result is the same for both:

I have turned on “Generate Mesh Distance Fields” in the rendering settings… Is there something else that I am missing?

Thanks in advance,

Set the generate distance field option in project setting > rendering

your cube is contributing to the global distance field, so naturally it’s coloured red

either disable distance field generation on the mesh, or in the details panel uncheck “affect distance field lighting”