Confusion about path argument in FObjectFinder

I’m trying to give my character class a skeletal mesh but am unclear how FObjectFinder works. I have 2 questions.

  1. What should the path argument be, and what is it relative to?
    For instance -


// Absolute path to asset file 
E:/Unreal/Projects/FPSProject/Content/Models/SK_Mannequin.uasset

// Absolute path to class .cpp source file 
E:/Unreal/Projects/FPSProject/Source/FPSProject/FPSCharacter.cpp


If I make this call from FPSCharacter.cpp …


static ConstructorHelpers::FObjectFinder<USkeletalMesh> 
        NewMesh(TEXT("/FPSProject/Content/Models/SK_Mannequin.uasset"));

… Will the directory “/FPSProject” be evaluated as



E:/Unreal/Projects/FPSProject/Source/FPSProject/

or 

E:/Unreal/Projects/FPSProject/


  1. What is the prefix of the path in FObjectFinder’s argument?
    In the following code, the argument is “StaticMesh’/Game/StarterContent/Props/MaterialSphere.MaterialSphere’”
    What is “StaticMesh” in that argument?


static ConstructorHelpers::FObjectFinder<UStaticMesh>
BaseMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Props/MaterialSphere.MaterialSphere'"));


Is it a class type, a file name, a directory?
What happens if you exclude it?

I’ve been stuck on this for a while, so any help would be appreciated.
Also any examples and explanations of how to use FObjectFinder, and how it works, would be very helpful.

Thanks!

The path is relative to your (or the engines, or a plugins) content folder. For example:
/Game/Folder/Asset.Asset will be /Project/Content/Folder/Asset.uasset on disk.
/Engine/Folder/Asset.Asset will be /Engine/Content/Folder/Asset.uasset on disk.
/PluginName/Folder/Asset.Asset will be something like /Engine/Plugins/PluginName/Content/Folder/Asset.uasset.

If you’re wondering about the Asset.Asset thing, that’s because you’re loading a uasset package called Asset and then the object that is also called Asset from that. Pretty much the only time you need to change this convention is when loading a blueprint, where you need Asset.Asset_C to get the generated class object.

The “prefix” lets you filter what type of object to load. It is more of a relict and not particularly useful, since you’re already filtering by class when loading things. I’d just leave it out.

Going back to your example, the path you want is “/Game/Models/SK_Mannequin.SK_Mannequin”

2 Likes

All our code is like this:



const FString CROSSHAIR_TEXTURE = "/Game/Textures/Icons/CrossHairAimPoint.CrossHairAimPoint";
 _textureCrossHair = ConstructorHelpers::FObjectFinder<UTexture2D>(*CROSSHAIR_TEXTURE).Object;


Has this practice changed? I’m using this method in 4.24 and am getting this error:


2>C:\Program Files\Epic Games\UE_4.24\Engine\Source\Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(110): error C2664: 'void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)': cannot convert argument 1 from 'T *' to 'UObject *'



I fixed similar error by including a corresponding header file, in this case a header for UTexture2D.