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):
a variable will be the best bet. a single variable really doesnt have that much cost anyway. most games have thousands of variables. you will never have a 100% optimized game, everything is a trade off, eliminating this one variable may be one less thing in memory but it may well cost you on the cpu instead.
The mesh material is a Dynamic
Instance for sure, there is just no
obvious way to get or cast it. (cast
fails)
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…
Please do not post answers like “save
it in a variable”! I care about my RAM
performance and would avoid any
unnecessary variables.
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.
As you see on the screenshot, it fails for my case. Even though i have assigned it a MID (material instance dynamic) at construction time using CreateDynamicMaterialInstance node.
i can argue regards keeping the reference to MID, because reference exists in RAM 24/7, while the operation that demands it only occurs rarely on special events. doesn’t worth it to store a variable for that.
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.
I come from the C++ world and i can definitely state i understand how pointers work.
a pointer is and implicit int type with 8 bytes length on x64 platforms, means if i have 1000 instances of an actor with this (mostly) idle pointer, i waste 8kb of RAM for practically nothing. should you use it more often and you end up with tens of wasted megabytes that could be used for other more important stuff.
I think I know why it’s failing for you. You might be creating the dynamic material directly in the object’s construction script. While this was possible in 4.15 and below (maybe even in 4.16), it’s no longer supported.
Instead, wrap the DMI creation in a function or use an event and call that in the construction script.
That should do it.
edit: Nah, scratch that. It’s working as is. Out of the box. I was thinking about widgets, you can no longer construct them there.
In case it still does not work:
I tested the MID in an empty project with a skeletal mesh and it seems to work fine (get scalar from a dynamic material assigned to skeletal mesh). Maybe you can show us how you create and assign the material. Is there anything out of ordinary there?