8. Reading parameters of the dynamic material

For creating different types of effects it can be very useful to read the parameters of a dynamic material. Let's read and output our emission color right after the effect we created earlier.

Img 30, Reading and outputting emission color


For our reading function, we need to create a variable placeholder that can contain the information of our color. You can see on line 38 of image 30 that I’ve created a FLinearColor placeholder called “ReadVector”.


To read a vector parameter, we need to use the “GetVectorParameterValue()” function contained in our dynamic material. The function needs the parameter name, which we declare in the first parameter slot. In the second parameter slot we put our “ReadVector” placeholder.


Next, we want to output our emission color to the output log of UE4. That way we can test if our code works. On line 40 of image 30 you can see how to do that. I am outputting the name of the object, following the read color.


Reading the scalar parameter value is similar.

Img 31, Reading and outputting emission strength


We need to change the type of variable for our placeholder. A scalar parameter is expressed as a “float”. I have called my placeholder “ReadScalar”.


To read a scalar parameter, we need to use the “GetScalarParameterValue()” function. Which also requires a parameter name and placeholder.


Finally, we output the read information to the output log of UE4, like on line 45 of image 31.


Your code should look like this:

Img 32, Total code of reading and outputting dynamic material values


Don’t forget to again compile your code before testing the code. Start the level and take a look at the output log UE4.

Img 33, Output logs of the dynamic materials


In the output log you can see that reading our values has worked. You can see the name of the object with their read values.


Popular posts from this blog

6. Creating and editing the dynamic material

5. Constructing a blueprint