DynamicMaterial breaks DecalComponent

I have an Actor that I’ve defined in C++ with a UDecalComponent. The material I’m using has some parameters that I want to change dynamically, so I create a DynamicMaterialInstance in the OnConstruction function of my actor:

 void ADecalTestActor::OnConstruction(const FTransform& transform)
 {
 	Super::OnConstruction(transform);
 	_decalMaterial = Decal->CreateDynamicMaterialInstance();
 }

I’ve found that if the actor is already placed in the level before I add this code, it works perfectly fine

But if I run the editor with that code snippet it just displays a grey-green texture instead

I was able to repro this with a new project using the simplest material I could think of

67518-simplematerial.png

It seems the problem lies with creating the DynamicMaterialInstance in the construction script but I’d like the decal to be accurate when viewing the level in the editor window and not just when playing the game.

Hello -

Can you take a look at this test project and see if you can identify (besides being a BP) any differences as to how you are calling your MID?

Thank You -

Eric Ketchum

Test Project 4.10.0

The only things that stood out to me were that the material for the decal was set in the class defaults instead of the details panel in the level and that I used the top-down template instead of an empty project. I made a BP-only project using the top-down template and was able to repro the problem. I’ve uploaded it to Dropbox - File Deleted

And in case you want to see it as well, my C++ test project is at Dropbox - File Deleted

Hi kgamble -

In your BP project, the Material you have used to create a Dynamic Material from is not set to be a Decal Material in the Material Attributes. This is necessary even if you are using a Dynamic Material Instance.

If you go into the Decal Material and Change the Material Domain from Surface to Deferred Decal, your Blueprint project will work correctly.

In your code project you have actually set up a Dynamic Material Instance but you have not told the MID exactly what Material to be created from. If you want that to be exposed you can create a variable linked to the UMaterial property in code that you can assign a Decal Material in the Editor. Currently you have only a MID that can be assigned, with no way to link a base material to it.

Thank You

Eric Ketchum

Thanks, got it working now. The BP one was just an oversight on my part, guess I just forgot to change its domain. For the C++ side, I guess I was confused by the order things were done. I had changed the material in the Details panel once I had placed it but it seems my code in OnConstruction was overriding that. Added something to set the material before creating the MID and it works the way I was expecting.

Hey Eric, sorry to break the resolved status of this post, but thanks to your helpful test project, I discovered why the decal’s dynamic material instance would always show up as the default decal material inside the level. Apparently, you cannot have the decal as the root of the blueprint, which means you cannot have a dynamic material in a blueprint whose Parent Class is decal actor. You must first choose actor, then manually add a decal component. This is how your BP test project was setup, and this is the only way that works. Not sure if that’s by design, or a bug.

Thanks again for your help!

-Adam