Hi,
So I’m creating a looting system where the loot inside of chests spawns loot based on a data table I have created. Every piece of loot has a certain rarity. Is there a way to automatically have the rarity linked to a material color or maybe a light color or something of that nature. Just for simplicity, I’d want common items to be green, rare to be blue, and legendary to purple for example. Is there a way that when the enum I have created of the rarity, it will automatically be mapped to a material instance as well? I know I can use a switch statement on the enum but it seems a little messy doing it that way. If that is the only way, that’s fine. I just wasn’t sure if there was a cleaner way of doing it.
Hi,
One approach is to use a Map, or dictionary: Working with Maps | Unreal Engine 4.27 Documentation
“They support efficient look-ups and retrievals of values with the use of associated keys.”
Here is an example you can try where you associated the rarity of an item (EItemRarity) with a Linear Color:
Here is how you create a map variable:
And finally, here is how you get the color based on an input rarity enum:
In this example, using the construction script of an actor blueprint (with a point light component), I update the light color based on the rarity of the item. Here is the final result:
Here is also a video on the topic: WTF Is? Variable: Map in Unreal Engine 4 ( UE4 ) - YouTube
I hope this helps, and good luck
Hi, I made a complicated Random-item Chest spawner in another project. Cant access now - but here is the simple version. The Chest spawns the BP Pickup, but also changes the light colors of chest parts, based on which Pickup-tier was spawned.
I did this by setting many variables in a DT, which use Rows (rows go up and down).
So the first Row can be named Weapon1. Then in the other columns (left to right) I added an Int variable, which I use to drive colors like this > each # represents a Tier strength, which is linked to a Linear color list on a Select Node (in the code of your Chest BP or Pickup BP).
So in this way, you can set Light colors and colorize Materials. (I put the code in Construct.)
-
For Mat changes, youll need a Master material that has white texture zones/masks (because it’s bad to colorize a red or blue texture since the color change will not be pure Hue).
-
And this Master must have a named Param for the Color.
-
Then you make an MI out of that Master, and assign it to a SM/SK in the editor.
-
Save the mesh asset, then add it to your DT as a variable. (So we have the row named “Weapon1” which now has another column of an Int of 3 = tier 3, and Mesh = mesh to use that has the White MI.)
-
Then in the code (not shown), at Construct, you make a DMI (Dynamic Material out of the MI), which the code can then modify the color of the “Color Paramater” linked to your Master mat.
-
In this pic, I think I didnt need to make a DMI, just dragged the Mesh part (that’s in the Chest) into the graph, and connected it to the Set Vector Parm node.