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"

Sharing Dynamic Material Instances

I have an actor with many attached StaticMeshActors. I want to modify the materials for all of them at runtime. I could get all the attached actors, and ForEach create a new Dynamic Material Instance, and modify that instance as desired. However, if I have 1500 meshes sharing 100 materials, I really only need to create 100 Dynamic Material Instances, not 1500.

I'd appreciate any advice on how to construct a Blueprint script that:

  • Creates a map/hash/association that can associate dynamic instances to materials.

  • ForEach of the attached actors, finds the material used.
    • If there is not already a dynamic instance associated with the material, it
      • creates a dynamic instance,

      • customizes it,

      • associates it in the map/hash,

      • and sets the actor to use it

    • If there is already a dynamic instance, sets the actor to use it

Alternatively (less optimal, but maybe easier to author?) it could be:

  • Find all the attached actors (1500 of them)

  • Find the unique set of materials they use (100 of them)

  • ForEach of the materials, create a Dynamic Material Instance with my own customizations.
    • Store these in a map/hash from original material to dynamic instance.

  • ForEach of the attached actors, replace the original material with the associated dynamic instance.

Product Version: UE 4.16
more ▼

asked Feb 06 '18 at 04:29 PM in Blueprint Scripting

avatar image

219 8 17 25

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

when you create the dynamic material instance, right click the bluepin on the right and promote it to a variable. Then set that variable in the foreach loop for all of them instead of creating a new one everytime. Any change you make the parameters in that variable will affect all of them.

more ▼

answered Feb 07 '18 at 02:10 AM

avatar image

1k 64 50 98

avatar image Gavin.Kistner Feb 07 '18 at 05:23 PM

Thanks for your reply. Can you be more explicit? Imagine that I have three meshes, A, B, and C. Meshes A and C use material M1, mesh B uses material M2. In my ForEach loop, when I get to C, how do I find out that there's already a dynamic instance based on M1 and apply that material instance to C, instead of creating a new dynamic instance and variable?

What I understand you to suggest is the following, which (AFAICT) makes a new value for the variable each loop. How do I associate the dynamic instance with the original material?

alt text

loop.png (129.9 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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