# Access Violation with Render Target Asset when using FObjectFinder

**URL:** <https://forums.unrealengine.com/t/access-violation-with-render-target-asset-when-using-fobjectfinder/410769>\
**Category:** Rendering\
**Tags:** access-violation, fobjectfinder, unreal-engine, Rendering, CPP, question\
**Created:** [November 28, 2017, 5:49am UTC](https://forums.unrealengine.com/t/access-violation-with-render-target-asset-when-using-fobjectfinder/410769 "2017-11-28T05:49:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_89fb8479](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_89fb8479](https://forums.unrealengine.com/u/anonymous_user_89fb8479)\
**Post date:** [November 28, 2017, 5:49am UTC](https://forums.unrealengine.com/t/access-violation-with-render-target-asset-when-using-fobjectfinder/410769/1 "2017-11-28T05:49:34Z")

</div>

I’m having trouble trying to load and access a Render Target asset from the content browser in my C++ class. Loading the asset seems to work fine using ConstructorHelpers::FObjectFinder in the constructor of the class, but when I try to access it later I get an access violation error. What exactly is going wrong with my code?

* * *

Here is the code in the class’ constructor:

```
// Initialize Root Component
RGBCameraRoot = CreateDefaultSubobject<USceneComponent>(TEXT("RGBCameraRoot"));
RootComponent = RGBCameraRoot;
	
// Initialize Camera
RGBCamera = CreateDefaultSubobject<USceneCaptureComponent2D>(TEXT("RGBCamera"));
RGBCamera->AttachToComponent(RGBCameraRoot, FAttachmentTransformRules::SnapToTargetNotIncludingScale);

// Initialize Render Target
ConstructorHelpers::FObjectFinder<UTextureRenderTarget2D> RenderTargetAsset(TEXT("/Game/Camera/Cap.Cap"));
RenderTarget = RenderTargetAsset.Object;

// Initialize Texture
Texture2D = CreateDefaultSubobject<UTexture2D>(TEXT("RGBTexture"));

// Set Camera Texture Target as Render Target
RGBCamera->TextureTarget = RenderTarget;

```

* * *

And here is my BeginPlay(), where I get the access violation error, specifically on the line where I attempt to construct a Texture2D out of the Render Target :

```
// Called when the game starts or when spawned
void AMyRGBCam::BeginPlay()
{
	Super::BeginPlay();
	RGBCamera->TextureTarget = RenderTarget;
	Texture2D = RenderTarget->ConstructTexture2D(this, FString("Texture2D"), EObjectFlags::RF_NoFlags);
}

```

* * *

Am I perhaps not using FObjectFinder correctly? I’m new to Unreal Engine, and I’d really appreciate the help!
