Get Landscape Color of an Actor Location

Hello!

I’m trying to get the landscape color, of the current position of an Actor - in real time.
So the color of the landscape where the actor is placed on.
So I refresh the Actor Location every tick. But then … is there an easy way?

Thanks for your hints.

I don’t think that’s possible, but if not, here’s a nice workaround.

Extend the UPhysicalMaterial class, and add an FLinearColor property to yours.
You can then create you PhysicalMaterials using the class you made, and paint them on the landscape with along with its textures.

Then if you use a Trace, it can easily see which physicalmaterial your actor is standing on at the moment, which has your custom color property in it. :slight_smile:

I use this method to make my landscapes create different footstep sounds/particles/prints when the actor runs along it.

Thanks a lot for your answer.
Unfortunately, I don’t unterstand it, but I’ve tried it. I made the material with the new PhysicalMaterial and its FLinearColor variable and I’ve added a Trace, which get the Landscape as result.
So I have now the Landscape as FHitResult.
But how you’re defining the FLinear Color?

FHitResult has a lot of properties in it, one of them being the Actor it hit (landscape), but it can also return the the PhysicalMaterial associated with that actor.



TraceParams.bReturnPhysicalMaterial = true;
bool hitSomething = world->LineTraceTestByChannel(start, end, collisionChannel, TraceParams);


Assuming your trace is similar to the above, you can use the first line to make it also return the PhysicalMaterial

Then after you have your FHitResult, you can grab it like this:



//Cast it to your custom class
UMyPhysMat* PhysMat = Cast<UMyPhysMat>(hitResult.PhysMaterial.Get());
DoStuff(PhysMat->Color)


That will allow you to pick up your custom physics material now from anywhere!

Just make sure you put your physics material in the LayerInfo file for each paint. That’s what lets each paint have it’s own physics material, and thus, it’s own FLinearColor/whatever else you add in there.

Edit: Incase it wasn’t clear, you’d make multiple Physics materials with all the colors you want, apply those and paint them into the landscape, and your character will now pickup your custom physica material colors as he runs around.

First, thanks a lot for all your effort!
That is a great idea. I think this works great with textures with only one color. But with these grass-dirt textures, this won’t work, because it’s the same paint (like your Grass-Dirt paint, number 3 in the example) and we don’t know on which part of the texture the actor is placed on (dirt or grass of the dirt-grass texture), I hope you know what I mean?
But it works if we mix it manually, so a complete grass layer and a complete dirt layer and then painted with a pattern.
Thank you!

I am trying to achieve a similar thing for a strategy game, trying to internally divide the landscape into “provinces” which are invisible (thinking about showing only the edges of the provinces) while also having a nice view through soil, dirt and similar textures. I tried physics materials as mentioned and it works well when there is just one material painted.
I have tried using a separate Landscape Layer for painting these provinces, while for painting the grass/dirt/etc I used a different layer, however in the end they all get merged together and sometimes grass/dirt wins, i.e. I get their physical material, instead of the province.

Is there any way to specify a layer and get only physical materials of a specific layer?
Any other solution?
@ Juice-Tin