Hi everyone,
I’m trying to build a program that, given a project path, would load at runtime a 3D scene. I’ve already done it using Unity 5, and I wanted to recreate the same product under Unreal to compare pros and cons. Right now I’m struggling creating a new material starting from some input parameters (i.e. the program reads a bool isReflective variable set true, and creates a new reflective material instance). Under Unity was quite easy because all I had to do was to load the proper shader, but I can’t find any parallelism under Unreal.
//Unity example
Material mat = null;
if (_transparency)
{
mat = new Material(Shader.Find("Transparent/VertexLit"));
}
Is there any easy way to create a new material instance from Engine/Shaders or any other already existing resource using C++?
you can also specify outer and a name and all that stuff. But what more interesting is that you can actually create material nodes in c++ and compile them. For example:
UMaterialExpressionConstant3Vector * BaseColorFactorNode = NewObject<UMaterialExpressionConstant3Vector>(NewMaterial);
BaseColorFactorNode->Constant = FColor::Red; //you can specify any color here;
UnrealMaterial->BaseColor.Connect(0, BaseColorFactorNode);
This will create a material with a const vector3d parameter in your material. I don’t know the limits of it, I only had to work with constants, textures and multiply nodes. Anyway, hope this help somebody.
Hi, no, I afraid it won’t. This code is used by the editor when it created material from export files. It can’t be done runtime. The way I did it was creating a material with parameters and some custom HLSL code to define behavior based on them(since standard material expressions don’t have too many logical nodes).