Setting a dynamic material to all meshes within a blueprint

So my level contains a blueprint, lets call it “RoomBP”. Inside that blueprint, I have other blueprints such as “WallBP”, “DoorBP”, etc. Each of these contain multiple static mesh objects. Many of the mesh objects share a common material.

Throughout the level I plan to spawn multiple instances of “RoomBP” dynamically (it is sort of a labyrinth game with puzzle elements). Each time a room spawns, I need to set all of the materials to use one of several base colors that I have defined. For example, a blue version of the room might spawn in which all of the wall, door and floor elements all use the same blue base color.

Is it possible to create a blueprint on the “RoomBP” level that will trickle down and effect the materials of all the sub-blueprints it contains and their child meshes? I would need to be able to spawn additional instances of the room that would use new colors, with out effecting the pre-existing ones.

You are for quite a bit of arrays fun. You need 2 custom events inside each “wallBP” “doorBP” etc blueprints

First event is very simple. Lets call it “update materials”. It should have array of materials as input parameter. All this event does is read that array, store it in local copy and call second event.

Second event we call “apply materials”, it applies all materials. It is a bit complicated:

  • you need array of “all mesh components” in blueprint “wallbp” “doorBP” etc. Create it during that BP construction time, each time you place mesh component, add it to this array.
  • you need array of “materials passed” from “update materials”
  • and you need array with integer “material index” values for each mesh component. Same as array of meshes, but instead adding mesh reference you add integer value that tells which material to apply.

The network:

Start with “ForEachArray Element”,
read with “foreach index value”: array “all mesh components” get stored reference
read with “foreach index value”: array “material index”
read with return value from above line: array “materials passed”

Now you should have reference to component from “all mesh components”
index which material to apply from: “material index”
and material reference from: “materials passed”

rest is simple create dynamic material instance, apply material you want to it, then apply it to mesh.

Reason for 2 events:

At event begin play fill up default array values for materials and call second event “apply materials” to apply materials.

Now when you create “wallBP” you can expose on spawn that array of materials (one you pass to “update materials”)
It should correctly read it and apply all materials during begin play.

Ps this all is kind of complicated to explain in text.

Thank you so much for your response, I’ll dive into this when I get home from work tonight. I only started working with UE4 about a month ago, but I’m making an effort to practice with it every day. This is the most complex thing I’ve tried to do yet and I’ve been banging my head against a wall with it for the last week. Wish me luck!

I am having a lot of difficulty replicating this. Could someone help me break this down into babysteps? I am new to a lot of these concepts.

Questions about this step:

  1. Do I make this in the construction script, or event graph of the blueprints?

  2. I have never made a variable that needed to be referenced in multiple blueprints before. Where should I create the array, and how do I then reference it from other blueprints.

Hope this helps

You quite possibly already solved your case, but i’ll post this anyway since it wasn’t too easy for me to find answer on this one.

I had similar problems but solved it here.

…in construction script.