How to edit a material in c++ directly

Hi, I want to create an instance of a material in c++ and dynamically change the material and update it in the HUD directly.

UMaterialInstanceDynamic NeuMat;

ConstructorHelpers::FObjectFinder<UMaterial> NewMat(TEXT("/Game/UI/HUD/tada.tada"));

No idea how to progress after that I cant create the MaterialInstanceDynamic.

Material instance needs to be created first. Theres a function in any primitive component (mesh etc.), to create and override material instance, it return UMaterialInstanceDynamic (create variable for that, in my case is MatInst) in which you can edit parameters:

MatInst = ((UPrimitiveComponent*)GetRootComponent())->CreateAndSetMaterialInstanceDynamic(0);

But the material is not present in any surface yet. I want to get the material instance then draw it in the HUD

But the material is not present in any surface yet. I want to get the material instance then draw it in the HUD

Your old question

Look there for a little info on CanvasRenderTarget. I am planning to use this as soon as I get to implementing a proper hud in my game.
Anyway, now I am drawing my materilaized :slight_smile: text with TextRenderActor, it is quite easy if you tie it to your camera.

	static ConstructorHelpers::FObjectFinder<UMaterial> MatFinder(TEXT("Material'/Game/Materials/Font/TextMaterial_Glow.TextMaterial_Glow'"));	
	if (MatFinder.Succeeded())
	{
		Material = MatFinder.Object;
		MaterialInstance = UMaterialInstanceDynamic::Create(Material, this);
		//Setting a font parameter of a dynamic material instance crashes the game when invoked in a constructor
		//using default font parameter until onconstruction
		//DamageTextMaterialInstance->SetFontParameterValue("Font", DamageTextFont, 0);
		MaterialInstance->SetScalarParameterValue("Glow amount", CurrentGlowAmount);
		MaterialInstance->SetScalarParameterValue("Opacity", CurrentOpacity);
	}
	else
	{	//use empty PCIP material (idk what to do, this is just a stub)
		MaterialInstance = new UMaterialInstanceDynamic(PCIP);
	}

	TextRenderComponent = PCIP.CreateDefaultSubobject<UTextRenderComponent>(this, TEXT("TextRenderComponent"), true);
	TextRenderComponent->SetMobility(EComponentMobility::Movable);
	/* Set location and rotation omitted... */
	TextRenderComponent->TextMaterial = MaterialInstance;
	TextRenderComponent->TextRenderColor = GlowColor;
	TextRenderComponent->Font = Font;
	TextRenderComponent->Text = FString("");

I am not entirely sure what exactly TextRenderColor does (I don’t need textures for my text), but here is a link with some textured text.

Thanks… Both of those helped me a lot.