How to set a texture to a dynamic material (pure c++)?

Hello,

I’d like to create a Media Player at runtime, and then put the corresponding UMediaTexture on a UMaterialInstanceDynamic.
The material is set properly (as I can see it on my mesh in the editor during runtime), however I cannot change its texture.

Here is my actual code :

	// Creates the associated media texture
	UMediaTexture* MediaTexture = NewObject<UMediaTexture>(this);
	MediaTexture->SetMediaPlayer(*MediaPlayer);
	MediaTexture->UpdateResource();
	MediaTexture->AddToRoot();

	// Creates a dynamic material and gives it the texture
	UMaterialInstanceDynamic* DynamicMaterial = NewObject<UMaterialInstanceDynamic>(this);
	DynamicMaterial->SetScalarParameterValue(FName("EmissiveColor"), 0.5);
	DynamicMaterial->SetTextureParameterValue(FName("BaseColor"), MediaTexture);
	DynamicMaterial->SetTextureParameterValue(FName(TEXT("DynamicTexture")), MediaTexture);

I’d like to do this in pure C++, with no intervention in blueprint nor material editor.

Thanks !

I figured out that my Dynamic Material had to inherit a material with a DynamicTexture parameter for me to be able to edit it. I gave up doing this parent material by code (if anyone has some example code I’d like to see this), so I did it in the material editor. I’m loading it dynamically and I create my dynamic material using it. The name of the parameter of SetTextureParameterValue() has to be the same as the name you chose in the material editor.

You can select which Shader you want any particular Material to use. Simply expand the Shader
drop-down in the Inspector, and choose your new Shader. The Shader you choose will dictate the available properties to change. The properties can be colors, sliders, textures, numbers, or vectors myprepaidcenter.com

I’m loading it dynamically and I create my dynamic material using it. The name of the parameter of SetTextureParameterValue() has to be the same as the name you chose in the material editor. my prepaid center

You Must loading it dynamically and I create dynamic material. دانلود آهنگ جدید

You Must loading it dynamically and I create dynamic material.