Hello guys, I am probably slowly becoming insane, I don’t understand why this doesn’t work: I am trying to load stuff (like a mesh) from a soft reference and not a hard one (TSoftObjectPtr
). SO I wrote the following code to do that:
void APickup::InizializePickup(const TSubclassOf<UItemBase> BaseClass) {
if(ItemDataTable && !ItemID.IsNone()) {
const FItemData* ItemData = ItemDataTable->FindRow<FItemData>(ItemID, ItemID.ToString());
ItemReference = NewObject<UItemBase>(this, BaseClass);
ItemReference->InizializeItem(ItemData->ItemInventoryData, ItemData->AssetsData, ItemData->InteractableData);
this->InteractableData = ItemData->InteractableData;
// TArray<FSoftObjectPath> AssetsToLoad;
// AssetsToLoad.Add();
AssetsHandle = UAssetManager::GetStreamableManager().RequestAsyncLoad(
ItemData->AssetsData.ItemMesh.ToSoftObjectPath(),
FStreamableDelegate::CreateUObject(this, &APickup::SoftActorRefLoaded)
);
// Set the mesh scale (not sure)
ItemMesh->SetRelativeScale3D(ItemMesh->GetRelativeScale3D() * ItemData->AssetsData.ItemMeshScale);
}
}
And the following is the code that is executed after the mesh is loaded:
void APickup::SoftActorRefLoaded() {
UE_LOG(LogTemp, Warning, TEXT("THE DELEGATE WAS ■■■■■■■ EXECUTED!"));
// Set the mesh
if(IsValid(ItemReference->GetItemAssetsData().ItemMesh.Get())) {
UE_LOG(LogTemp, Warning, TEXT("THE ASSET WAS ■■■■■■■ LOADED SUCCESSFULLY!"));
}
ItemMesh->SetStaticMesh(ItemReference->GetItemAssetsData().ItemMesh.Get());
}
Both the logs get executed but the StaticMesh
is not displayed.
The mesh is loaded only if I drag the static mesh from the content browser in the scene before running the “game” and I don’t get why. In the table
where I get the row everything is setup correctly and the reference mesh is saved as a TSoftObjectPtr<UStaticMesh>
. When the actor is destroyed in the BeginDestroy()
I cancel the handle AssetsHandle
:
void APickup::BeginDestroy() {
Super::BeginDestroy();
// if the handle was not already destroyed, destroy it
if(AssetsHandle && AssetsHandle->IsActive()) {
AssetsHandle->CancelHandle();
}
}