Get DynamicMaterialInstance from Mesh?
Is there a way to get DynamicMaterialInstance from a mesh instead of a regular Material? I need to read one of it's scalar values i am often setting.
The mesh material is a Dynamic Instance for sure, there is just no obvious way to get or cast it. (cast fails)
Please do not post answers like "save it in a variable"! I care about my RAM performance and would avoid any unnecessary variables.
You can read it like this:
Providing the static mesh has been assigned a MID, the above cast will work just fine. To be perfectly honest, you definitely should store the MID reference and use that instead - it is way more performant than casting...
Not sure why you would even say something like this. Perhaps you should look into what a pointer is to understand its memory footprint. If performance is of utmost importance, consider abandoning blueprints altogether and do things directly in C++. For example, the cost of that cast is most likely an order of magnitude larger that storing a pointer.
Anyhow, both are borderline negligible unless you're firing it in a loop hundred times per frame.
I found a couple of documentation sources on our docs.unrealengine.com that might be of help. If this isn't quite what you are looking for, please let me know and I will try my best to assist you. Here are the links to Instanced Materials and Material Parameter Collection (There are also other links on these pages that might might be of better help):
answered Jan 26 '18 at 08:46 PM
Natalia Q ♦♦ STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here