Having trouble with USceneCaptureComponent2D, UTextureRenderTarget2D, and MIDs




void AWeaponRailgun::BeginPlay()
{
Super::BeginPlay();

ScopeCam = NewObject<USceneCaptureComponent2D>();
ScopeCam->Activate(false);
ScopeCam->FOVAngle = 10.f;
ScopeCam->AttachTo(SkeletalMeshComponent, FName("ScopeFeed"), EAttachLocation::SnapToTarget);
RenderTarget = NewObject<UTextureRenderTarget2D>();
RenderTarget->SizeX = 1024;
RenderTarget->SizeY = 1024;
UMaterialInstanceDynamic* ScopeMat = UMaterialInstanceDynamic::Create(AssetScopeMat_Default, this);
ScopeCam->TextureTarget = RenderTarget;
ScopeCam->bCaptureEveryFrame = true;
ScopeCam->UpdateContent();
FTextureResource* RenderTex = RenderTarget->CreateResource();
ScopeMat->SetTextureParameterValue(FName("ScopeFeed"), RenderTarget);
SkeletalMeshComponent->SetMaterial(ScopeMatIndex, ScopeMat);

}




It changes the texture from the default, but all I get is gray; not the gray tiles, but solid 0.5 gray. Does anyone have any ideas on why this doesn’t work? I haven’t really been able to find any non-blueprint documentation.


ScopeCam = NewObject<USceneCaptureComponent2D>();
	ScopeCam->FOVAngle = 90.f;
	ScopeCam->AttachTo(SkeletalMeshComponent, FName("ScopeFeed"), EAttachLocation::SnapToTarget);
	RenderTarget = NewObject<UTextureRenderTarget2D>();
	RenderTarget->InitAutoFormat(1024, 1024);
	UMaterialInstanceDynamic* ScopeMat = UMaterialInstanceDynamic::Create(AssetScopeMat_Default, this);
	ScopeCam->TextureTarget = RenderTarget;
	ScopeMat->SetTextureParameterValue(FName("ScopeFeed"), RenderTarget);
	SkeletalMeshComponent->SetMaterial(ScopeMatIndex, ScopeMat);

So, I changed the material so it takes the texture param straight into the emissive and nothing else going on. This gives me green. Any reason why It is green? When I add a scene capture in the level and set its texture target to a RT in the content browser, it works, so why not here?