How to Create material using C++ and apply it to static mesh?
I want to apply material to my Static mesh using C++, now i know that there is "StaticMesh->SetMaterial()" function, but the problem is this function is taking UMaterialInterface as a parameter and i could not find any way to convert my UMaterial* UnrealMaterial to UMaterialInterface ?
Another problem is, what is the difference between UMaterialInterface and UMaterial ?? And why instead of taking UMaterial in StaticMesh->SetMaterial() it is taking UMaterialInterface ?
So anyone know how to do it ?
Thanks in advance.
Ok to answer to each one of your questions.
You should not need to convert from UMaterial* to UMaterialinstance* since UMaterial inherits from MaterialInstance. If for some reason the code is complaintning simply cast to it Cast(YourMaterialPointer).
Material interface is an interface that allows you to pass any material type into functions that use materials as arguments (like in your case), since there are several material types (UMaterialInstance, UMaterialConstantDynamic, UMaterialInstanceDynamic, etc).
The function takes Material Interface as a value for the reason stated above (so it can receive any material type).
Hope this information helps you. If this is the information you needed please remember to mark this answer as the correct one so other people can find it. Make it a great day!
answered Mar 11 '19 at 10:39 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here