Hi, i’m creating a editor tool for unreal engine, this tool should create a new Material (UMaterial) and add node (aka UMaterialExpression) to its expressions and then connect this node to the outputs (like BaseColor, Roughness, Metallic, Opacity).
I started creating this tool in Unreal Engine 4 and everything was fine, the code to do this was:
//UsedMaterial is a UMaterial* defined in the .h as a class variable.
//and it is created like this:
FString MaterialBaseName = "M_Material_" + GetName();
FString PackageName = "/Game/";
PackageName += MaterialBaseName;
UPackage* Package = CreatePackage(NULL, *PackageName);
UMaterialFactoryNew* MaterialFactory = NewObject<UMaterialFactoryNew>(); // Create an unreal material asset
UsedMaterial = (UMaterial*)MaterialFactory->FactoryCreateNew(UMaterial::StaticClass(), Package, *MaterialBaseName, RF_Standalone | RF_Public, NULL, GWarn);
//Create a Texture Sample Node
UMaterialExpressionTextureSample* TextureRTMaskExpression = NewObject< UMaterialExpressionTextureSample>(UsedMaterial);
UsedMaterial->Expressions.Add(TextureRTMaskExpression);
//UsedTextureMask is a UTextureRenderTarget2D* alredy created at this point of code
//(it isn't null)
TextureRTMaskExpression->Texture = UsedTextureMask;
//... Other code
//finally i connect the UMaterial BaseColor expression to my //UMaterialExpressionTextureSample called
//'TextureRTMaskExpression' created before
UsedMaterial->BaseColor.Expression = TextureRTMaskExpression;
All fine here, but now i’ve switched to Unreal Engine 5.1.1 and this property and methods are deprecated or modified.
first problem is:
UsedMaterial->BaseColor.Expression = TextureRTMaskExpression;
now BaseColor is called BaeColor_DEPRECATED and can’t be accessed.
The problem is i can’t find a new method or a property to di the same thing, and so my question is: how is managed now the material expression in c++?
second problem is this part:
UPackage* Package = CreatePackage(NULL, *PackageName);
This code line give me a warning like this:
warning C4996: ‘CreatePackage’: Use CreatePackage overload that does not take the first Outer parameter. Specifying non-null outers for UPackages is no longer supported. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
if someone can explain me how the code i made for Unreal 4 is made now for Unreal 5.1.1 would be very helpfoul.
thank you in advance!
(And sorry if my english is not perfect, and sorry if there is alredya topic on this but i searched for hours here, in the documentation and on the internet but nothing)