Problem with FObjectFinder Outside Constructor

ANLevant
Fri, 28 Aug 2020 16:58:10 +0000
Character & Animation

So this is my code:

 TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
 TSharedRef< TJsonReader<> > JsonReader = TJsonReaderFactory<>::Create(*response->GetContentAsString());
 if (FJsonSerializer::Deserialize(JsonReader, JsonObject)) {
            FCraftableData craftableData = JsonToCodeableItemMapper::MapAToB(*JsonObject);
            ACharacter* PlayerCharacter = GetOwningPlayer()->GetCharacter();
            ACraftable* CreatedItem = GetWorld()->SpawnActor<ACraftable>(ACraftable::StaticClass(), PlayerCharacter->GetTransform());
            CreatedItem->Initialize(craftableData);
            UE_LOG(LogTemp, Warning, TEXT("Instantiated!"));
        }

ACraftable’s Initialize method:

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

	FString AssetName = ACraftable::CraftableData.AssetPath;
	FString AssetPathName = "SkeletalMesh'/Game/Models/CreatedItems/" + AssetName + "." + AssetName + "'";
	Super::BeginPlay();
	ACraftable::ItemMesh = ConstructorHelpers::FObjectFinder<USkeletalMesh>(*AssetPathName).Object;

	UE_LOG(LogTemp, Warning, TEXT("%s"), *ACraftable::ItemMesh->GetFullName());
}

I am trying to create an Actor with a varying SkeletalMesh depending on what the HTTP Response is.
The issue here is that FObjectFinder can’t be called outside Constructor, and constructor can’t be sent parameters, as to tell him which is the correct mesh and REST Data.

I need either a way of fetching the mesh outside the constructor, or send parameters to constructor

4 posts - 1 participant