How to capture post-processing

In the blueprint, I just need to check Post-Processing in the SenceCaptureComponent2D component and change the CaptureSource to the FinalColor enumeration to capture the post-processing effect, as shown:

But I set these in CPP will not work:

// Public FPreviewScene and place the component in another world.
RenderScene = MakeShareable(new FRendererWidgitPreviewScene());

#pragma region CaptureComponent
	CaptureComponent = NewObject<USceneCaptureComponent2D>();
	CaptureComponent->TextureTarget = InArgs._RenderTargetTexture;
	
	// SCS_FinalColorLDR
	CaptureComponent->CaptureSource = ESceneCaptureSource::SCS_FinalColorLDR;

	USceneCaptureComponent* Archetype = Cast<USceneCaptureComponent>(CaptureComponent->GetArchetype());
	if (Archetype)
	{
		CaptureComponent->ShowFlags = Archetype->ShowFlags;
	}
	// Check “PostProcessing” as in the blueprint; Help: Is this the right setting?
	FString ShowFlagName = FString("PostProcessing");
	int32 SettingIndex = CaptureComponent->ShowFlags.FindIndexByName(*(ShowFlagName));
	CaptureComponent->ShowFlags.SetSingleFlag(SettingIndex, true);

	FEngineShowFlagsSetting PostSetting;
	PostSetting.Enabled = true;
	PostSetting.ShowFlagName = ShowFlagName;
	CaptureComponent->ShowFlagSettings.Add(PostSetting);

	RenderScene->AddComponent(CaptureComponent, CameraTransform);

#pragma endregion CaptureComponent
	// Add UPostProcessComponent
	OutLinePostComponent = NewObject<UPostProcessComponent>();
	// Set Custom Depth Render Material
	OutLinePostComponent->AddOrUpdateBlendable(InArgs._OutLineMaterial,1.f);
	RenderScene->AddComponent(OutLinePostComponent, FTransform());

	// Add Mesh
	if (InArgs._CubeMesh.Num() != 0)
	{
		for (int i = 0 ; i< InArgs._CubeMesh.Num();i++)
		{
			UStaticMesh* Mesh = InArgs._CubeMesh[i];
			FName MeshTag = FName(*InArgs._CubeMeshTags[i]);

			auto MeshComponent = NewObject<UStaticMeshComponent>();
			MeshComponent->SetStaticMesh(Mesh);
			MeshComponent->ComponentTags.Add(MeshTag);

			MeshComponent->SetRenderCustomDepth(true);

			RenderScene->AddComponent(MeshComponent, MeshTransform);

			MeshComponents.Add(MeshComponent);
		}
	}

	CaptureComponent->UpdateSceneCaptureContents(RenderScene->GetScene());

I’m trying to render the model in another world and get its screen through CaptureComponent, but it doesn’t work, now I can capture the model, but not the post processing effects.

Please help with the problem, thanks.


	for (UStaticMeshComponent* MeshComponent : MeshComponents)
	{
		MeshComponent->SetWorldTransform(MeshTransform);
		MeshComponent->SendRenderTransform_Concurrent();
		MeshComponent->MarkRenderStateDirty();
	}
	OutLinePostComponent->MarkRenderStateDirty();
	//OutLinePostComponent->MarkRenderTransformDirty();

	CaptureComponent->SetWorldTransform(CameraTransform);
	CaptureComponent->UpdateSceneCaptureContents(RenderScene->GetScene());

I am calling the above update code in OnPaint, is this correct?