Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Change Landscape Material/Textures at Runtime?

I know UE's landscapes are perfectly static and there is generally no way to create or modify them at runtime without the editor.

I got used to the fact that I can't alter any height- or material-weight data at runtime (with a heavy heart...), but I still haven't given up on trying to exchange the entire landscape-material instead. The point is to be able to apply a snowy material when it's snowing, a "wet" material when it's raining etc.

I tried a couple of things, but without success. Unfortunately, dynamic material instances don't seem to work with landscapes.

Then I thought I had found a workaround by iterating through a landscape's components, setting their override-material to whatever I want them to use, and then calling their member-function UpdateMaterialInstances(). But as it turns out, that function is editor-only as well :(

Does anyone have a workaround for this?

Product Version: UE 4.12
more ▼

asked Jul 28 '16 at 07:46 PM in Rendering

avatar image

643 65 82 116

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

AFAIK, you can't change those at runtime. Why don't you make snow and wetness as a part of your landscape material though?

more ▼

answered Aug 08 '16 at 01:51 PM

avatar image

7.8k 130 31 293

avatar image MaxPower42 Aug 09 '16 at 08:45 PM

Actually I found a kind of workaround to use dynamic material instances with landscape components. It's dirty, but it works...

avatar image BlueberryFox Dec 29 '17 at 11:47 AM

Hi MaxPower42, Im trying to change materials for my landscape aswell. Would you mind to share some of your code? Or do you have some more detailed explanation. I would really appreciate it!! Thanks alot!!

avatar image MaxPower42 Jan 02 '18 at 08:38 AM


  1. I haven't actually used the code in a long time, so there is a chance that it doesn't even work anymore.

  2. It's using a kind of hacky cast, because I set an MID where an MIC is expected. I didn't have any problems at all with it, but if your computer explodes, don't blame me, you have been warned...

That said, if you have a pointer "Landscape" to your landscape-actor, you could try something like this:

     for (int i = 0; i < Landscape->LandscapeComponents.Num(); i++)
         ULandscapeComponent* C = Landscape->LandscapeComponents[i];
         if (C->IsRenderStateCreated())
         for (int j = 0; j < C->MaterialInstances.Num(); j++)
             if (!C->MaterialInstances[j]->IsA(UMaterialInstanceDynamic::StaticClass()))
                 C->MaterialInstances[j] = (UMaterialInstanceConstant*)UMaterialInstanceDynamic::Create(C->MaterialInstances[j], GetTransientPackage());// HACKY CAST!
             UMaterialInstanceDynamic* MID = (UMaterialInstanceDynamic*)C->MaterialInstances[j];
             for (int k = 0; k < Env->Textures.Num(); k++)
                 MID->SetTextureParameterValue(pn[k], Env->Textures[k]);

"pn" is an array of specific texture-parameter names to set and Env is an "Environment Descriptor"(c) class instance that has a specific array of ground texures and other stuff.

This does not change anything about the material weighting or even height data on the landscape, only replaces the weighted materials with different and dynamic ones. If you want to achieve the former, I don't know if it is possible. I think you can access the height and weight data textures somehow, but I wouldn't be too optimistic that you can change them as easily.

avatar image BlueberryFox Jan 03 '18 at 06:27 PM

Thanks alot!! I will try it out in a couple of days!!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question