I have followed the Procedural Mesh Generation Tutorial (Good Stuff). Then Added UV Support as outlined in This Thread
I am generating simple quads. When I drag them out into the editor, or spawn them at runtime, I get the default checkerboard patten (which I assume is a good thing). But I cannot change the material that is used (drag and drop). Now I don’t really need the drag and drop functionality and I have been told that a simple “YourMeshComponent->SetMaterial(0,TheMaterial);” should do the trick. But I do not know how to access Materials from my project. Forgive me if this question has been answered already, I have searched Forums and AnswerHub to no avail.
The second option would be to instead of finding the material in your project through the code in your constructor like above would be to use UPROPERTY for example
If you have created a class blueprint for this current class then this is a more visual approach producing a Material variable in your blueprint where you can select any material within your project, just be sure to create a dynamic instance of the material which ever way you decide to do this so your materials can be changed at runtime.
ConstructorHelpers::FObjectFinder<UMaterial> MaterialHandSpriteLoader(_T("Material'/Game/Widgets/Textures/Hand/MAT_3DIcon.MAT_3DIcon'"));
if (MaterialHandSpriteLoader.Succeeded())
{
UMaterial* M = (UMaterial*)MaterialHandSpriteLoader.Object;
UMaterialInstanceDynamic* MaterialInstance = UMaterialInstanceDynamic::Create(M, this); //<- Although compiled, the error is caused by this
}
Log:
Unknown exception - code 00000001
(first/second chance not available)
"Fatal error:
[File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.10\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp]
[Line: 2646] NewObject with empty
name can’t be u
UMaterial* M = (UMaterial*)MaterialHandSpriteLoader.Object;
UMaterialInstanceDynamic* MaterialInstance = UMaterialInstanceDynamic::Create(M, this); //<- Although compiled, the error is caused by this
Probably is because you are triying to Create the material in a class that is not inherited from an UObject (like AActor), so you can’t use “This”, because this is referred to an UObject.