|
| 1 | +The Material API |
| 2 | +---------------- |
| 3 | + |
| 4 | +Unreal has 3 "kind" of materials: |
| 5 | + |
| 6 | +* Material - this is the base for the following two types, this is where you define material nodes and properties, it must be compiled to generate the required shaders. |
| 7 | + |
| 8 | +* Material Instance - when you want to modify parameters of a material you do not need to create a whole new material, but you can create an 'instance' of it. The instance shares the logic of the parent material but changes specific properties (like textures). |
| 9 | + |
| 10 | +* Material Instance Dynamic - sometime you may want to change the properties of a material instance at runtime, in such a case you need to generate a special matrial instance that is mapped to a specific object while your game runs. |
| 11 | + |
| 12 | +Assigning a material to a primitive component |
| 13 | +--------------------------------------------- |
| 14 | + |
| 15 | +Once your material (instanced or non instanced, constant or dynamic) is ready, you want to assign it to a PrimitiveComponent: |
| 16 | + |
| 17 | + |
| 18 | +```py |
| 19 | +component = self.uobject.get_actor_component('Mesh') |
| 20 | +material = ue.load_object(Material, '/Game/Materials/Iron') |
| 21 | +component.set_material(index, material); |
| 22 | +``` |
| 23 | + |
| 24 | +Creating a Material (editor only) |
| 25 | +--------------------------------- |
| 26 | + |
| 27 | +```py |
| 28 | +from unreal_engine.classes import Material |
| 29 | +new_material = Material() |
| 30 | +new_material.set_name('New Funny Material') |
| 31 | +new_material.save_package('/Game/Materials/NewFunnyMaterial') |
| 32 | +``` |
| 33 | + |
| 34 | +Creating a Material Instance (editor only) |
| 35 | +------------------------------------------ |
| 36 | + |
| 37 | +You have two ways to create a instanced material: |
| 38 | + |
| 39 | +(new_material is a reference to a previously created/loaded material) |
| 40 | + |
| 41 | +```py |
| 42 | +from unreal_engine.classes import MaterialInstancedConstant |
| 43 | + |
| 44 | +material_instance = MaterialInstancedConstant() |
| 45 | +material_instance.set_name('New Funny Material Instance') |
| 46 | +material_instance.set_material_parent(new_material) |
| 47 | +material_instance.save_package('/Game/Materials/instanced') |
| 48 | +``` |
| 49 | + |
| 50 | +or the shortcut: |
| 51 | + |
| 52 | +```py |
| 53 | +import unreal_engine as ue |
| 54 | +# the material instance will get the name of the parent with the _inst suffix |
| 55 | +material_instance = ue.create_material_instance(new_material) |
| 56 | +``` |
| 57 | + |
| 58 | +Creating a Material Instance Dynamic |
| 59 | +------------------------------------ |
| 60 | + |
| 61 | + |
| 62 | +Listing, getting and chaning available material properties |
| 63 | +---------------------------------------------------------- |
0 commit comments