How to use Dynamic Material Instance on Billboard in C++?

How can I create a DynamicMaterialInstance of a material instance in UE4, and set it on a material billboard?

I’ve tried every combination I can think of, all I want to do is have an en-editable material billboard with a dynamic material instance on it, and set some of the scalar parameter values. Ideally, I want to be able to use a static material instance too as opposed to a variable, so I figure I can do this using the ConstructorHelpers library?

I need to be able to access that material instance anywhere in the corresponding class, to set values in it.

Bump, these are still completely broken so it seems!

1 Like

Bump - Material Billboards still don’t support Dynamic Materials correctly.

1 Like

Here’s what I did:

// in constructor
static ConstructorHelpers::FObjectFinder<UMaterial> Material(TEXT("Material'/Game/Materials/UI/Game/M_Reload.M_Reload'"));
	if (Material.Object)
	{
		ReloadDisplay->AddElement((UMaterialInterface*)Material.Object, nullptr, false, 32.0f, 32.0f, nullptr);
	}

Then

void ACannon::OnConstruction(const FTransform& Transform)
{
	Super::OnConstruction(Transform);

	if (ReloadDisplay->Elements.Num() > 0)
	{
		FMaterialSpriteElement& ReloadSpriteElement = ReloadDisplay->Elements[0];
		ReloadMaterial = UMaterialInstanceDynamic::Create(ReloadSpriteElement.Material, ReloadDisplay);
		ReloadSpriteElement.Material = ReloadMaterial;
	}

}

Thanks Cobryis, I’ll give that a shot. Some of that stuff is impossible to call in Blueprints - so those users will still suffer.

Hi TheJamsh -

It looks like as of 4.8 P1 this issue has been addressed to expose Material Billboards to the same control as you would expect in a blueprint. I have attached a very simple test map, if I am missing a functionality you are wanting please let me know -

Thank You

Eric Ketchum

Test Project 4.8 P1

Thanks Eric,

Unfortunately Cobyris’ method didn’t work for me. I had to do another workaround, eventually got it working but it wasn’t very smooth. I had to create the dynamic material first then set it on the Billboard.

I still don’t think it allows runtime changes though.

Hi -

I am confused my test project shows a setup in which a MID is created from a MIC and assigned in the Construction Script, then in the event graph a Scalar and Vector Parameter are changed on “K” Pressed events. What exactly are you trying to call in Blueprints that you still cannot?

Thank You

Eric Ketchum

I did this in blueprint originally, and to make it work I got the material info from Elements then clear elements and used AddElement with a new dynamic material. I believe it worked, but that was a while ago.