Landscape material swap

Hello -
Our artists would like to, at runtime, change the material applied to the terrain in our levels. I’ve been looking through the code in the landscape system and this does not look like a straightforward thing to do - it appears there is only editor side functionality for this. Am I missing some mechanism for doing this at the moment? Is this a feature that might be supported at some point?

Thanks!
Erik

This is not supported in-engine, because each landscape component creates a material instance of the landscape material in order to optimise the shader for that component.

Hi Gareth -
Sorry for the delayed reply but I was just wondering - in your estimation how difficult would it be to simply have that process be applied to a set of materials instead of a single one and and then swap them in/out at runtime?

This is going to be a fairly important feature for us so I just want to see if you have any advice on how to approach it.
Thanks!
Erik

The key functions to look at are ULandscapeComponent::UpdateMaterialInstances() and ULandscapeComponent::GetCombinationMaterial(). My advice for material swapping would be to create a new uasset for a “landscape material set”, change GetCombinationMaterial() to reference whatever asset is assigned to the landscape to find the combinations (instead of Proxy->MaterialInstanceConstantMap) and store the created combination materials as children of the asset (instead of GetOutermost()).

ULandscapeComponent::UpdateMaterialInstances() could probably be altered to create UMaterialInstanceDynamic’s instead of ULandscapeMaterialInstanceConstant’s if in-game, and then it would be able to be used in-game (maybe a few other bits of code might need to be updated for that possibility too).