Help, Materials, Parameters and C++ Problem
I can't get my head around this. I am sure Unreal has a clean/elegant solution for this.
I have found 2 Possible solutions I would like to Implement, but I can't get it working.
I have also found an ugly solution.
The ugly solution is getting all the UMaterialInstanceDynamic and update the parameters that needs, checking if that parameter is needed (an exception is thrown if when a parameter that the material Instance doesn't have is set).
The Nice Solution 1 would be to have a ParameterCollection specific for that character and that set of Materials. But as far as I know, ParameterCollectionInstances belong to UWorld and only one is created per ParameterCollection;
The Nice Solution 2 is to bind a C++ function to the material, so when each parameter is needed by the Materials that function is executed.
What should I do?, Please help!
Hi. You can create a new actor (not scene) component ( UParamAnnouncerComponent or something like this ) which will walk thru the actor hierarchy and set dynamic instances on meshes which default material have specific parameters. Also this component should save information about that material instances. At least you have to store TArray of UMaterialDynamicInstances weak references there to refresh all parameters when you need. Using weak references prevents from memory leakage when you change some materials on your character. If you change some material ingame old dynamic instance is still be referenced from the TArray without using weak refs. Also this component can hold previous variables for parameters (or hashes - it will be less complicated) and perform actual update only when something is really changed instead of each frame updates.
When created this component can be attached to any character or static object you want and expose some update functions to a blueprint.
How to get param names if you have a material reference:
answered Jun 09 '17 at 10:12 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here