Scale Texture Across World Space

Hello All, Wondering if anyone can give me a hand.
I’m currently making a tile based game, and I have a material set up for the tiles that change the colour based on the meshes height in the world (set-up below). It achieves the look i’m going for, however I’ve run into several issues. The texture sample is just a 1 pixel wide strip of colour that i’ve used to determine colour that gets scaled up across the world space.

For starters, not all of the meshes its used on are of the same height, and so when it comes to scaling the material upwards on the Z co-ordinate across the world, it’d be different for each of them. At the moment, i’ve got the ‘HeightOffset’ variable which just moves the material, up or down a bit which fixes this issue but its a pain to adjust constantly for every different mesh its applied on. I also want to use the same material/set-up on a grass material so that the grass colour will always match the colour of the tile its on, but that obviously won’t work with my current setup because again, the height of the grass mesh won’t be the same as the tile meshes i’m using and the scaling won’t match up.

What I’d like is for there to be a way to stretch the texture sample across the world space once, starting and stopping at a particular height, so that I can use that same material in multiple meshes and they all line up to each other regardless of the height of the mesh and the scaling of the material. In short, all three of the Hexes above should be the same colour without me having to go in and adjust the ‘HeightOffset’ Parameter.

I hope that makes it clear.

While I haven’t done it myself yet, If I am understanding you correctly, I think this might be what you are looking for which is a Seamless Tileable Texture based on World Space Alignment: Seamlessly Tiling Material - [UE4] - YouTube

Additionally, if you wanted to take it a step further, it could be combined with an Auto Landscape Material: Unreal Engine 4 - Landscape Auto Material - YouTube

Cheers. That’s less fixed it. The ‘Object Position’ node I’ve realised was also the thing messing it up.