Change Landscape component material at game run-time?

Blueprint:

I can Create Dynamic Material Instance, use Set Material function (Target is Primitive Component, the node says so) for StaticMeshComponent.

However, for LandscapeComponent, neither Set Material function nor Set Override Material (just an exposed property, although BlueprintReadWrite) works, nothing happens using them.

Thanks!

===============================================================================

C++:

I even can write a function, SetOverrideMaterial(UMaterialInterface* Material), in ULandscapeComponent:

OverridedMaterial = Material;
UpdateMaterialInstances();
MarkRenderStateDirty();

The component’s material is changed, but is shown as the default material (checker), although in Blueprint if I get that Overrided Material, Get Base Material, it is the material I set.

===============================================================================

Note:

ULandscapeComponent::GetLandscapeMaterial() in Landscape.cpp is inclosed in “#if WITH_EDITOR”.

All references to ULandscapeComponent::OverrideMaterial are inclosed in “#if WITH_EDITOR”.

The 2 threads are ABSOLUTELY different, “350990/landscape-material-lods” is asking if there’s an existing material LOD feature, this one is asking a specific issue (which has its own complexity to warrant a new thread) when trying to implement our own. See how much distracting information was put in “350990/landscape-material-lods”, I don’t think further questions can be discussed there now.

I think the target for the dynamic material instance should be the mesh, not the Primitive Component, unless its the mesh object itself, but if that’s not it, there is a different way of doing it which I prefer, because it allows gradual changes, basically it involves changing material properties at runtime, its the one way I know how to do this so far:

(Dynamic Snow tutorial by Liaret)

Materials can be assigned to StaticMeshComponent, or LandscapeComponent (Landscape mode > Manage > Selection tool to select components > Override Material). It’s components.

I think you can only change material instance parameters at run-time, but not material properties like Tessellation.

Changing the entire material in UpdateMaterialInstances is really heavyweight and isn’t suitable for use outside the editor.

But we should be able to make a change so the landscape components have a MaterialInstanceDynamic in the front of them, allowing the user to adjust parameter values for nodes that were created in the original Landscape Material.

I’ve just added a feature request for that under UE-24979

At the moment each component has a MaterialInstanceConstant which points to another MIC (which is shared between components with the same layer usage) which finally points to the LandscapeMaterial.

The final MIC is stored in the MaterialInstance property of the LandscapeComponent. You could change that property to be a MaterialInstanceDynamic and change the code in UpdateMaterialInstances to create a M.I.D instead, under the comment “// Create the instance for this component, that will use the layer combination instance.”.

After making this change and then modifying the LandscapeMaterial, each component should be allocated its own MaterialInstanceDynamic and you should be able to change parameters on it at will.

If you do end up getting this to work, please consider submitting a pull request.

Thank you for the info, !

I want to use 2 MIDs: MIDNear and MIDFar. Everything else is the same between the 2, except MIDNear has Tessellation. I probably don’t need to change parameters.

Components are large enough, if at any time at most 4 components use MIDNear, a camera movement will results in about 2 components changing materials dynamically.

So, I should need another map (like LandscapeProxy’s MaterialInstanceConstantMap) for the Far material.

I want something like what is implemented here:
https://ogre3d.atlassian.net/browse/OGRE-204

@anonymous_user_442235c0 : any update on this? UE-24979 does not exist anymore, what is the status of dynamic material instances for landscapes? In my testings it doesn’t seem to work on 4.18.2.