How to detect the material of a terrain at a specified vector

I am trying to create a construction script that raycasts to a random point on a terrain, and if the landscape layer is grass, then place a tree blueprint. If the material is sand, then don’t place a tree. How would I achieve this?

There is a nice explanation here about how to setup and detect surface types using physical materials by DempaG - Different Footstep Sounds on Different Materials - Unreal Engine Forums
Note that for me, I had to restart the project to get the Physical Surfaces entered in the project settings>physics to appear nicely (set as default remained greyed). I think the defaultengine.ini needs to be read on startup. Maybe different in different engine version though I guess.
Hope this helps get you started. Bear in mind that there may be another way that I don’t know.

That was really helpful! Thanks!