x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.18
Tags:
more ▼

asked Jan 22 '18 at 12:24 AM in Blueprint Scripting

avatar image

Arty-McLabin
848 18 40 59

avatar image Arty-McLabin Jan 26 '18 at 12:39 PM

bumpy bump

avatar image ThompsonN13 Jan 27 '18 at 09:09 PM

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.

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

You can read it like this:

alt text

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...

alt text

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.

capture.png (67.8 kB)
capture2.png (30.7 kB)
more ▼

answered Jan 28 '18 at 08:37 AM

avatar image

Everynone
12.6k 72 24 53

avatar image Arty-McLabin Jan 28 '18 at 12:35 PM

alt text

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.

screenshot-5.png (52.8 kB)
avatar image Everynone Jan 28 '18 at 03:26 PM

Is the material set to be used with Skeletal Meshes? It's a tickbox in the material editor.

avatar image Arty-McLabin Jan 28 '18 at 04:40 PM

yes, it is

avatar image Everynone Jan 28 '18 at 05:39 PM

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?

avatar image Everynone Jan 28 '18 at 05:55 PM

Is there anything that's different from this?

alt text

This prints 1.25 for me which I set in the material:

alt text

capture.png (167.9 kB)
capture2.png (46.7 kB)
avatar image Arty-McLabin Jan 29 '18 at 11:47 AM

wow. i am feeling so dumb. the resolutions are always so obvious..alt text

thanks for your help, it pushed me to recheck it second time.

screenshot-6.png (32.8 kB)
avatar image Everynone Jan 29 '18 at 02:03 PM

We've all been there, done that. Glad to hear you have it working!

Good luck.

(comments are locked)
10|2000 characters needed characters left

Hey Arty-McLabin:

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):

https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/ParameterCollections/

https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/MaterialInstances/#materialinstancedynamic

Regards,

Natalia

more ▼

answered Jan 26 '18 at 08:46 PM

avatar image

Natalia Q ♦♦ STAFF
565 2 3 3

avatar image Arty-McLabin Jan 27 '18 at 08:50 PM

it does not answer the question in any way :(

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question