I don’t understand why when using the GetMaterial using the index does not work with CreateDynamicMaterialInstance function.
I have a static mesh with a material at slot index 0.
In the construction script, I create the dynamic material instance.
If I use the GetMaterial using the index 0, I cannot change a parameter from the material instance.
Ok. That means getting a material instance defined in static mesh and creating a dynamic material instance does not work well.
I changed and I have defined a material instance var and creating the dynamic material instance. And it works,
What?? Is this still true for UE4.27? I can’t make a Dyn Mat Instance from a Material Instance already applied to a Mesh???
How can I overcome this restriction? Because I have Master materials and then 10x texture sets, that each need new Textures plugged in for Base, Normal, OCC, etc.
So instead of making 10x Master Mats, I made 10x Instances, which are faster to switch out the textures/ all the settings are in a panel.
And I used code like your first pic: Create Dyn > But I cant plugin ‘Get Material’ (which is an MI) - code fails.
But I also cant dropbox select a ‘Named Source Material’ because some meshes use a different Master/MI (e.g. Panners vs Transparent Mats) = code fails for all Meshes except ones that use that Named Mat.
So what can I do to “Get Material” (of wildcard Meshes in an array), which use multiple versions of MIs – and create Dyn Mats, so I can edit Params in game?
(Im using Dyns to set live colors, with a mesh that has an MI with White color zones - which fill in with color based on the Param, instead of making 10x copies of Meshes with diff colors.)
I vaguely looked at Material Collections. But their Params are restrictive in the Material code. It forces us to use 4 vector, which messes up some code that needs 3 vec. And if I’m using a “BaseColor” Parmam for 5 types of Master Material code, then it’s hard to make all the alterations match - when some use only 3 vec, or some textures are Masked to use only R,G.
But if ‘Material Collections’ are a way to use ‘Get MI’ node, and create Dyn from that > to edit Params, then please clarify.
Thanks for the reply. I cant get parent mesh in the way you showed (because Parent has a different Mat too), but appreciate the pic.
And I cant test an idea I have til a few hours. So can you clarify:
The ‘Get Material’ ONLY works on “Materials” and cannot work on “Material Instances” - is that correct? Some type of code restriction?
If true, then perhaps I can CastTo MI, Get Parent (Material), then Get Material (of Parent)? > to then make Dyn Mat > to set Param?
Think of it as of creating another DMI. We cannot use a DMI to make a DMI. But we can use DMI’s parent material to create another DMI.
If true, then perhaps I can CastTo MI, Get Parent (Material), then Get Material (of Parent)? > to then make Dyn Mat > to set Param?
Pretty much this!
I dont understand the relationship between Static Mesh and Static Mesh 1 in your pic, since they arent the same Mesh.
I probably assumed too much and went too far, thinking you want to instantiate an existing DMI and assign it to another static mesh. Apologies for the confusion.
Yes! lol, thats what I want. No worries.
I have a Pickup actor that has the SK mesh with the DMI and changed Color Param.
I want to pass this exact SK mesh (with its changed DMI) to the Player BP.
But my problems are:
The Pickup Actor has placeholder “Skeletal Mesh Components” (which have no asset set (because it reads from DT, to get the Construction display), and which are not real variables in the BP). So I have to convert SK component to SK mesh. And also convert SK mesh to Skinned Skeletal Mesh, because it’s using a Pose animation. (The meshes are body armor SK meshes, with a skeleton. Thus not basic Meshes.)
The Pickup Actor reads a DT at the Construct script, to pull a SK mesh (with a White colored MI applied), and pulls a color code modifier, which gets applied to the DMI, made from the White MI).
But the problem is I have this Construct script with 4x nodes of the same Function (because Loop nodes were hard crashing the Engine). So a set of 4x variables/Meshes pass thru the Function. Here, I can plugin “Get Material” into the “Source Material” to use. And somehow it worked to changed the Construction display of my Pickup actor, which contains 4x SK meshes with different Master materials. Thus it shows Head armor, Top armor, Legs, Boots - put together like a mannequin without a face/body. (So even before BeginPlay(?) these Meshes have a DMI assigned - from the Construct code.)
Pic 1:
But the same code isnt working in the Character BP, to plugin “Get Material” (wildcard for 4x meshes) into the “Source Material” to use.
The next problem is passing these DT edited SK meshes to the Player body (Modular SKmeshes). In Char BP, I tried to repeat the code to make the SK from the DT, with the color code. Pic 2: Maybe my DMI order is wrong, and getting a Material from blank SK comps that have no material?
But “We cannot use a DMI to make a DMI.” Or this is my problem. But I dont understand because I believe I was making a fresh SK mesh from the DT (not the exact SKmesh0034053 from the Pickup Actor that had a DMI).
Sorry for the messy addons - not final. Thanks for your time. Let me know if you need to see the other code parts to see the problem.
Edit: problem fixed in my post below - can ignore these pics.
Can someone please help? Here is a crop from the code above.
Does this [Add Unique] node act like a [For Loop]? (It is a Function in the Char BP, which is called from the Pickup BP, which has this Function called in a Loop.)
If the Function gets called with a Category of “Top armor” (with a Name of “Armor1”), yet my Player already has top armor Category, but with Name “Armor2,” then does this [Add Unique] ignore the change or add/update the slot?
Because what is happening (in Pic 2), there’s 2 paths for the Color code. It is working if the DT has a Color of anything not Alpha = 0, then code goes to False = Path 2:
I cant use Create DMI on a SK Mesh Object Reference (the actual SK asset in the DT, that has an MI applied).
So I get the Skinned Mesh path, use it to Set Skeletal Mesh with SK Mesh Object Ref.
Then I again use Skinned Mesh path to Get its Material > Make DMI > change Color of the MI that is associated.
And this works. The Armor changes to the correct Color (live in the game; and Construction update is already working before BeginPlay - before Player gets the Pickup).
But now if I get a different Pickup that is set with No DT color change (Its DT row has a color of Alpha = 0 to be the ‘NO change’ bool Condition). Then the code uses True = Path 1.
This top Path 1 has no DMI code at all. The Mesh should use whatever MI is already applied to it (pulled from the DT).
Yet the prior DMI (from prior Pickup = Path 2 mesh) is being applied to the new Pickup Mesh of Path 1, which doesnt even use the same DMI or MI. So what is wrong?
It seems that [Add Unique] isnt updating the Material? Or for Path 1 logic, do I need to clear the prior Path 2 DMI?
The guy who showed me the code for Add Unique, never finished the tutorial series and doesnt answer questions on Youtube. Thus Im trying to add what he didn’t, and unsure how. Thank you.
I fixed it by adding a Temp Skinned Mesh Component variable (which seems to help the code replace the old Mesh/Mat when it runs the cycle/loop).
The Yellow boxes are the fixes.
So this works to rebuild the Mesh from the DT, and set a DMI with color change, and Meshes without Color change code - get their original MI applied correctly.
The remaining problem is How to recycle/get the Prior DMI Mesh from the Pickup actor, and send it to the Player BP to use? Thank you.