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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How do I change a material color at runtime?

I ma making an atmosphere simulation that has a grid of cubes for visual representation. I want the material on each cube static mesh to change color according to a float variable. I can create this behavior except for one problem, I can't figure out how to change a material's base color in C++.

I have tried the examples below and it doesn't work.

 UMaterialInterface* mat = cube->GetMaterial(0);
 UMaterialInstanceDynamic* dMat = CreateDynamicMaterialInstance(0, mat);
 dMat->SetVectorParameterValue("color", FLinearColor::Red);

I don't need help with the color change code I just need to know how to access the material's color. Thanks to anyone that helps.

Product Version: UE 4.20
more ▼

asked Sep 13 '18 at 12:02 PM in C++ Programming

avatar image

Russ Rockjaw
16 8 10 11

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

1 answer: sort voted first

You need to have a parameter in the material you are trying to edit with the same name as the one you are trying to pass into that function, in your case a vector parameter with the name "color".

more ▼

answered Sep 14 '18 at 01:04 PM

avatar image

815 30 25 104

avatar image Russ Rockjaw Sep 17 '18 at 07:44 PM

Are the parameters already on the material or do I need to make one? Also what about when it says the SetVectorParameterValue() is in accessible, is that just a intellisense error?

avatar image cridia Sep 18 '18 at 12:19 AM

No, you need to setup one yourself, because you can use vector parameters for almost everything in the material editor (color is just a very basic example of using it).


As for the inaccessible, that may be just an intellisense error. As long as it compiles, there should be no problem. I use the SetVectorParameter function a lot myself and never had any problems with it thus far.

avatar image IndieGameCove Sep 17 '18 at 11:52 PM

you have to make it in the material editor. to do so right click on the constant vector node that your are using for color and select "convert to parameter" name it "color".

avatar image Russ Rockjaw Sep 19 '18 at 03:06 AM

Thank you both for the help. I was able to figure it out because of you.

(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