take a look at unreals Instanced Materials system.
It allows to create materials that change their behaviour depending on control variables (parameters).
Binding these as Material Instance Dynamic (MID) object it is possible to change their behavior on runtime. In your case change the color depending on your X value.
Create a material instance and add one scalar parameter. Set your parameter with your current X value and then change your color appropriate.
“Get Location of Spline Points” has to be “WorldSpace” of course.
And I don’t know how you handle the diffrent meshes you need at “Set Material”
And you need diffrent materials or some other variable you can change so the color changes too.