How to set Dynamic Material to Mesh With Dynamic Render Target?

I am trying to create Actor, which has Capture 2d Component and draw it on itself.
So, I create C++ class from StaticMesh Component, and implement it like this

AMyClass::AMyClass()
{
	SceneCapture = CreateDefaultSubobject<USceneCaptureComponent2D>(TEXT("SceneCapture"));
	
}

 

void AMyClass::PostInitializeComponents()
{
	Super::PostInitializeComponents();
	 
	UTextureRenderTarget2D* RenderTarget2D = UKismetRenderingLibrary::CreateRenderTarget2D(this, 1024, 1024,
        ETextureRenderTargetFormat::RTF_RGBA32f, FLinearColor::Black, false);
	SceneCapture->TextureTarget = RenderTarget2D;
	UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(ParentMaterial, this);
	
	material->SetTextureParameterValue(TEXT("TextureInput"), RenderTarget2D);
	GetStaticMeshComponent()->GetStaticMesh()->SetMaterial(0, material);
}

After Initializing actor I create render target, set it to capture component, then create dynamic material , set texture to render target, and apply material to Mesh.

Parent material blueprint very simple and provided above.
If I put this actor to scene, it does not change the material and editor crushed with access violation error in Render Thread.
Where is my mistake?

Hello! Smth wrong around creating of you Render Target Texture. You can try to create Render Target Texture in Content of proj (making it persistent) and using it. Another solution - check out that created texture is not garbage collected…