How can i cast an obejct i got with ConstructorHelpers::FObjectFinder to what i actually need ?

I use this line:


static ConstructorHelpers::FObjectFinder<USkeletalMesh> skeletal_mesh(TEXT("SkeletalMesh'/Game/Monsters/Imp/Imp_SkeletalMesh.Imp_SkeletalMesh'"));

And i want to use it as USkeletalMesh to assign it to the “Mesh” variable of the built-in character class.
Like this:


Mesh->SetSkeletalMesh(skeletal_mesh);

But it says:


Error	2	error C2440: 'type cast' : cannot convert from 'ConstructorHelpers::FObjectFinder<USkeletalMesh>' to 'USkeletalMesh *'	C:\OldSchoolNightmare\Source\OldSchoolNightmare\Imp_Character.cpp	15	1	OldSchoolNightmare

Hello !

I would recommend that when you run into a problem like this, you do a solution search for similar usage patterns (if you use Visual Studio: ctrl+shift+f and then select “entire solution” under “look in”). You will end up with a lot of references to the particular usage pattern for most problems this way.
Another way to find the info you need in cases such as this is to check out the tutorial projects. You can find them as templates when you select “create new project”.

The solution to your particular problem can be found in most template projects’ HUD classes for example:
From FPS template HUD class in ctor:



// Set the crosshair texture
	static ConstructorHelpers::FObjectFinder<UTexture2D> CrosshiarTexObj(TEXT("/Game/FirstPerson/Textures/FirstPersonCrosshair"));
	CrosshairTex = CrosshiarTexObj.Object;


So in your case you would have to do:



 Mesh->SetSkeletalMesh(skeletal_mesh.Object);


Best regards,

1 Like

Thanks for solution and the advices, i will keep that in mind :slight_smile: