The three virtues of a programmer: Laziness, Impatience, and Hubris. – Larry Wall
UE3:Create a MaterialInstance
Material instances can be created either within the Unreal Editor or at runtime from UnrealScript.
Contents
From within the editor[edit]
This is a page about a basic procedure related to the Unreal Editor. You are encouraged to link this page from other pages instead of explaining the procedure there. |
Creating an instance of a material in the Unreal Editor is as easy as right-clicking on the Material in the Generic/Content Browser and selecting Create New Material Instance (Constant/Time Varying) if the package containing the Material isn't cooked.
If the Material's package is cooked though, those menu options will be grayed out in the Generic Browser and you need to create the material instance manually in an uncooked package via right click -> New MaterialInstanceConstant/TimeVarying. The material instance properties window for the new instance should pop up, if not just open it manually. Use the Generic Browser to find the material you wanted to create the instance for and assign it to the instance's Parent property.
From UnrealScript[edit]
This is a page about a basic procedure related to UnrealScript. You are encouraged to link this page from other pages instead of explaining the procedure there. |
There are two ways to create MaterialInstances from UnrealScript.
Auto-replace on an Actor's mesh[edit]
If you want to modify parameters of a material already assigned to a specific Mesh, you just call the function CreateAndSetMaterialInstanceConstant(index) or CreateAndSetMaterialInstanceTimeVarying(index) on the MeshComponent(UDK, UT3), with index being the material slot to create a MaterialInstance for. The functions automatically replace the material on the actor so any changes, like setting material parameters, become immediately visible on that actor and only on that actor.
Just create instance for a Material[edit]
If you need an instance of a Material in general, you need to create it manually:
local MaterialInstanceConstant MIC; MIC = new class'MaterialInstanceConstant'; MIC.SetParent(ParentMaterial);
Here the ParentMaterial is the Material you are creating the instance for.