Why is my C++ UMaterialInstanceDynamic not accepting parameter changes?
EDIT: Further investigation reveals that the material is updating fine - variables edited on the instance of the component attached to the actor just aren't updating.
I'm working on a character customization system component in C++, and I'm having trouble getting my MIDs to update. I have materials declared in my header like this:
and I'm attempting to set vector and texture parameter values from both C++ and Blueprint. However, any change I try to make to the instance is silently rejected, and the actor I have this component attached to doesn't update. I've tried changing my MID variables from BlueprintReadOnly to BlueprintReadWrite, but that didn't help.
My source file looks like this. The last two functions are a product of desperation, and they aren't applying any changes either. The last function contains some debug that should print the updated colour, but only prints out the default value.
Okay, I managed to fix it!
The problem was a classic PLBCAC (problem lies betwen chair and computer), and I had misunderstood how InitializeComponent was fired. I was under the assumption that it only fired on BeginPlay and was as such not useable for me. This is not the case, and it fires as a last-step construction event.
Moving all of my logic to InitializeComponent allows all values to be loaded and initialized correctly before I attempt to access them, and my mesh gets everything assigned properly. Having the logic in PostEditChangeProperty sort of worked, but it produced a quick flash of my MID before all materials reset.
So, in short - PLBCAC, move logic to InitializeComponent to fix most anything.
A big thanks to everyone who helped out on the way!
answered Apr 10 '15 at 01:07 PM
Where is the Value "Key" set?
Make sure you use the text menu and that the names match the parameter in the material perfectly. It IS case-sensitive in some cases.
You could just replace "Key" with : TEXT("ParamName")
answered Apr 10 '15 at 08:43 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here