Problem with FObjectFinder Outside Constructor

I solved it. To anyone in the future getting references to that stupid unexisting wiki page, here’s the answer:

1- Do what everyone recomends, forget about the Constructor option (just create an empty subobject for your mesh), create a method initialize and call it right after your SpawnActor:

ACraftable::ACraftable()
{
...
 	// Set this actor to call Tick() every frame.  You can turn this off to improve 
	ACraftable::ItemMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MeshComponent"));
	ACraftable::ItemMeshComponent->SetupAttachment(PickupRoot);
...
}

On the Initialize Method you will retreive the Asset from the directory as a StaticLoad. Now be ware that this is actually something everyone suggests against doing. I had to do it because my game absolutely requires it.

void ACraftable::Initialize(FCraftableData InputCraftableData)
{
	ACraftable::CraftableData = InputCraftableData;

	FString AssetName = ACraftable::CraftableData.AssetPath;
	FString AssetPathName = "SkeletalMesh'/Game/Models/CreatedItems/" + AssetName + "." + AssetName + "'";
	Super::BeginPlay();
	ACraftable::ItemMeshComponent->SetSkeletalMesh(Cast<USkeletalMesh>(StaticLoadObject(USkeletalMesh::StaticClass(), NULL, *AssetPathName)));

	UE_LOG(LogTemp, Warning, TEXT("%s"), *Cast<USkeletalMesh>(StaticLoadObject(USkeletalMesh::StaticClass(), NULL, *AssetPathName))->GetFullName());
}

I hope this helped you, and please Epic Games, fix this b#11$#!t!!!

3 Likes