Hiya,
I’m trying to set up a material where one of a handful of colours are selected at random when the player presses a button. I already have the input mapping set up, but I’m struggling to figure out a way to get the colour change working. I thought I’d try using a Switch node in the material and then use a randomly-generated integer to drive the Switch Value, but I don’t know any way to call that parameter from the character blueprint where the input (in this case, pressing the E key) will happen OR how to create a random integer action in the material. I’ve been scouring the internet all weekend, but so far the only answers that come close to what I need are well above my skill level as a beginner programmer.
If there’s a better way to achieve this, I’m open to suggestions!
(Also worth noting that I will need to do this for multiple materials containing different texture sets, so I can’t do anything that can only be unique)
You need to make a dynamic material instance in the actor being modified (either in construction script or begin play) then set a material parameter on the instance when you want it to change. If color is to be driven by an int, make an int var on the color shifting actor and make it instance editible ( click teh eyeball by the variable in bp). if you create the dynamic mat in conscript and set the param there, you should be able to preview the colors in level viewport by changing the int in the actor’s details.
To let the player change the colors, you’ll either need to cast to this actor type and call a function on it to make a random int and set the mat parameter, or make a blueprint interface to do it. Interface would be better because it would avoid had casts, and each dynamic object could have its own logic and parameters in the implemented interface event.
You’re a star, thanks!! It took a bit of playing around to find a suitable method of interacting with the affected object, but getting the colours to change was exactly as you said 