How do I access assets in the content folder from c++

What are the “best practice” conventions for accessing assets in my content folder from a c++ file? I have found ConstructorHelpers::FObjectFinder and LoadObject, but I couldnt get LoadObject to work.

maybe you are adding the wrong path?
to get the right address: right button over an asset and select COPY REFERENCE and it will keep the right path in the buffer so you can CTRL+V it

static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshAsset(TEXT("StaticMesh'/Engine/VREditor/Devices/Vive/VivePreControllerMesh.VivePreControllerMesh'"));

Assign from anywhere:

UMaterialInterface* mat = LoadObject<UMaterialInterface>(nullptr, TEXT("Material'/Game/MAterials/BaseMat.BaseMat'"));

creating a component in an actor:

UCameraComponent* Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera0"));

creating a generc object:

UMyObject* MyObject = NewObject<UMyObject>();
1 Like

when initializing a generic object the following solution has appeared to work for me up until now at least

UMyObject* MyObject = new UMyObject();

Thanks eldany.uy! I’ve been struggling with this for a week. In hindisght it doesnt seem so hard…

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.