Can a material change its visual appearance based on distance to actors?

Update to a very old topic, but here is a way to do it based on a specific object (can probably be done with multiple as well with some tweaking).

Create a Material Parameter Collection (Material Parameter Collections | Unreal Engine Documentation) and create a Vector variable.
In a blueprint that ticks (level blueprint or something else), get the World Location of an object, and store that in the MaterialParameterCollection (split the pin and use the “Set Vector Parameter Value” node to input the X/Y/Z to R/G/B).
In the material you want to know the distance to the object, add a “Collection Parameter” node and link to your MaterialParameterCollection, and pick the value you saved previously.
If you need to compare it to the pixel/vertex (not sure) you are currently shading, use the “Absolute World Position” node in the Material Editor, and then break out the values you want from that to compare and do whatever magic you need.

I used this to create a grass that bends away from the player character moving around in it.