Can I get a color value from a location?

Hello everyone,

I have a scene on my game that involves a grassy landscape. Since it is on mobile, I can’t densely populate it all with grass. However, I would like to have patches of grass here and there that would render once it comes into a specific range.

Since my landscape (which is a static mesh because the actual landscape tool makes the game frame-y) has some random generation to vary the color in different patches, the grass that I lay down will also need to have this variation of color to reflect this, or there will be inconsistency in color.

So the problem is… how do I get the color from the landscape mesh? The first thing that pops into my mind is to get the landscape color from the location of the grass mesh and apply it? Is that even possible? If not, how else would I go about doing this?

Thanks in advance,


It’s possible from a trace even to get the material (Out Hit Phys Mat). Maybe you can do something with that info? I’m not sure what that something would be, but maybe a place to start?

What I would do is probably save the color information to a variable before applying it to the mesh and pull the data from there. You may need to make a struct to tie location data to that depending on how your function is setup currently. Its definitely possible, though.

I tried a few things, simply getting the physics material will only give me the phys name that I applied to that material, nothing about color values.


What I need is to get the color from the trace hit, which means that multiple areas of the material will give me multiple results. Here is a fake image I made in Photoshop to help express what I need:


It may not currently be possible with blueprint. I found this…
It looks like it’s something you could do with C++.

And this is vertex paint information, and not a general pixel information, which I’m guessing is easier than getting pixel info.

I guess this is something I can’t do for now. I’ll see if I can find another solution.

Thanks everyone!

Can I see where you randomize the color? Is it just in the material properties?

I don’t have it with me, but what I am doing is taking the grass texture and desaturating it (except negative so it actually oversaturates), and then feeding it into a lerp (lerp B). I take the base texture and feed that into lerp A. The alpha is a clouds texture. This results in patches of varying saturation. There’s more to it than that but that’s the gist of it.

Now, another idea is to just apply this to the grass texture as well, but getting it to line up with the base landscape mesh properly might prove very difficult.

Couldn’t the random generation that varies the color in different patches be stored as a variable to be accessible by the grass that gets put in it?


You could generate your random colors with names attached and apply those to the material names that come out of the Line Trace. That way you will always have the color for the situation.

I don’t know how to do it in unreal, but you could use data in the level to generate the shade on both objects. Minecraft for example has a gradient map that their tree’s and grass pull their color from based on a 2d vector on the co-ordinate they are at.

Hello you can use “SceneCaptureComponent2D” in actor to create a texture and use “Read render target raw pixel” to get the color.
Be careful to the size of the texture!

Hi, old post but I was passing by while looking for pixel related stuff.

Judging by your comment I think you could have done it by applying your cloud texture using worldspace UV and using the same coordinate in your grass material then lerping the same colors --Which you could eventually get from your landscape material using a blueprint to pass the info. Or even having the blueprint directly feed the colors value in both material
You might have to do some work with the UVs of your grass object, depends on how detailled the could texture is and if your grass moves. Since the color would depend of a worldspace noise, it may vary when the vertex of the grass are offseted by wind. But it also could be a interesting effect for a stylized kind of grass

Hope that can be of use for someone !