change material based on location

I am building a 2d tunnel (during run time) using a spline and would like to change the color of the material based on the location of the spline i.e.

  • Above ground X > 0 opaque
  • below ground X between 0 and -1000 brown
  • below ground X between -1000 and -2000 grey

is this even possible with a material? can anyone point me in the right direction?

Thanks loads

Hi there,

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.

Here is the documentation:
Instanced Material Documentation

Not sure how your BP looks like, but I would change the Construction Script like this somehow

“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.

Thanks for the response. Do you have any tips on adjusting the material from 1/2 the mesh, from a point onwards like “x greater than 0”, shown in red?

Thanks for the response. Do you have any tips on adjusting the material from 1/2 the mesh, from a point onwards like “x greater than 0”, shown in red?

Not really. I am sorry.