# UMaterialInstance vs UMaterialInstanceDynamic

**URL:** <https://forums.unrealengine.com/t/umaterialinstance-vs-umaterialinstancedynamic/360268>\
**Category:** Rendering\
**Tags:** unreal-engine, bug-report, CPP, question\
**Created:** [June 10, 2016, 1:34am UTC](https://forums.unrealengine.com/t/umaterialinstance-vs-umaterialinstancedynamic/360268 "2016-06-10T01:34:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pelangi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pelangi](https://forums.unrealengine.com/u/Pelangi)\
**Post date:** [June 10, 2016, 1:34am UTC](https://forums.unrealengine.com/t/umaterialinstance-vs-umaterialinstancedynamic/360268/1 "2016-06-10T01:34:50Z")

</div>

I’ve been searching for an answer for changing the TextureParameterValue of a material instance from code but had no luck. So here’s the problem. In my Playercontroller I made this simple code:

TestDesktopPlayerController.h:

```
UCLASS()
class ATestDesktopPlayerController : public APlayerController
{
	GENERATED_BODY()

public:
	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	UTexture2D* mCustomTexture;

	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	UMaterialInstanceDynamic* mCustomMaterial;

	ATestDesktopPlayerController();
};

```

TestDesktopPlayerController.cpp:

```
ATestDesktopPlayerController::ATestDesktopPlayerController()
{
	bShowMouseCursor = true;
	bEnableClickEvents = true;
	bEnableTouchEvents = true;
	DefaultMouseCursor = EMouseCursor::Crosshairs;

	int32 width = 40;
	int32 height = 40;
	TArray<FColor> data;
	for (int32 i = 0; i < 1600; i++)
	{
		data.Add(FColor(0, 0, 255, 255));
	}
	FCreateTexture2DParameters params;
	params.bDeferCompression = false;
	params.bSRGB = true;
	params.bUseAlpha = true;
	params.CompressionSettings = TextureCompressionSettings::TC_Default;
	params.SourceGuidHash = FGuid::NewGuid();
	mCustomTexture = FImageUtils::CreateTexture2D(width, height, data, this, FString(TEXT("CustomTexture")), EObjectFlags::RF_Public, params);

	// Structure to hold one-time initialization
	struct FConstructorStatics
	{
		ConstructorHelpers::FObjectFinderOptional<UMaterialInstanceDynamic> ChildMaterial;
		FConstructorStatics() : ChildMaterial(TEXT("Material'/Game/Material/ChildMaterial.ChildMaterial'")){}
	};
	static FConstructorStatics ConstructorStatics;
	if (ConstructorStatics.ChildMaterial.Succeeded())
	{
		mCustomMaterial = ConstructorStatics.ChildMaterial.Get();
	}

	if (mCustomMaterial && mCustomTexture)
	{
		mCustomMaterial->SetTextureParameterValue(FName("Diffuse"), mCustomTexture);
	}
}

```

I made ChildMaterial as material instance from ParentMaterial in UE editor.

 ![94073-parent+material.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/f/5/cf51c7ed2614e3ad9951e6ce065eaeed8a24418d.jpeg)

 ![94074-child+material.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/d/e/0dee6175a182f4652f01a702ace5db4247b8ce80.jpeg)

![94075-path.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/b/8/6b8d2925fbcbd489876b82593a8060e6b25cac4f.jpeg)

Everything seems to be in place and I’ve seen many samples in Answerhub and Forum that use `UMaterialInstanceDynamic`, instead of `UMaterialInstance`, to manipulate textures. The problem is, UE cannot find my `ChildMaterial` material instance if I use `ConstructorHelpers::FObjectFinderOptional` with `UMaterialInstanceDynamic` as template parameter.

![94076-not+found.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/a/5/3a540edc2f449711cc43ae2c32b919405ddc1fd0.jpeg)

But if I change it to `ConstructorHelpers::FObjectFinderOptional` with `UMaterialInstance` as template parameter, then it can be found. Is this a bug in UE?

What’s the difference between `UMaterialInstance` and `UMaterialInstanceDynamic`? When is the perfect time to use each of them?

Because I notice that `UMaterialInstanceDynamic` is a subclass of `UMaterialInstance`. So why can’t `ConstructorHelpers::FObjectFinderOptional` find the asset?

---

<div class="post-metadata">

**Author:** ![Sean\_Flint](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sean\_Flint](https://forums.unrealengine.com/u/Sean_Flint)\
**Post date:** [June 10, 2016, 3:22pm UTC](https://forums.unrealengine.com/t/umaterialinstance-vs-umaterialinstancedynamic/360268/2 "2016-06-10T15:22:42Z")

</div>

Hello,

After looking into your issue, the problem here seems to be that you’re looking to a UMaterialInstanceDynamic, but your ChildMaterial is a UMaterialInstance.

```
ConstructorHelpers::FObjectFinderOptional<UMaterialInstanceDynamic> ChildMaterial;

```

Based on your screenshot of the Material Instance, it appears that Child Material is a UMaterialInstance, which would be why you are unable to find it when searching for a Dynamic Material Instance.

Think of it like this:

You have an Actor class in your game. You use FObjectFinder to try and find a Pawn class. Your original class is an Actor, and even though Pawn is a subclass, it will not be able to find the parent class.

Based on what I’m seeing here, it would appear that in order to find the MaterialInstanceDynamic, you’d need to first create one and then search for it.

Also, just for reference, here’s our documentation on Material Instances: [Instanced Materials | Unreal Engine Documentation](https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/MaterialInstances/)

Let me know if that doesn’t make sense or you think it’s not correct, and I’ll be glad to try and provide additional information.

Have a great day
