This problem has been bothering me at Several weeks。
The StaticLoadObject() it aways is Null with return Value;
Who can help me ?
void AMyFPS_Character::test_asynLoad()
{
FPakPlatformFile *temp_pakFile = new FPakPlatformFile();
IPlatformFile* temp_platform = &FPlatformFileManager::Get().GetPlatformFile();
IPlatformFile *temp_platform1 = NULL;
temp_pakFile->Initialize(temp_platform, TEXT(""));
if (!FCoreDelegates::OnMountPak.IsBound())
{
return;
}
FString engine_dir(FPaths::GameContentDir().Append("PAK/")); // = FPaths::GameContentDir().Append("PAK/");
FString mount_file = FPaths::GameContentDir().Append(TEXT("DLC/OutPak.pak"));
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, *engine_dir);
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, *mount_file);
FPakFile pakFile(*mount_file, false);
if (!pakFile.IsValid())
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("FPakFile IsInvalid"));
return;
}
pakFile.SetMountPoint(*engine_dir);
if (!temp_pakFile->Mount(*mount_file, 0, *engine_dir))
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Mount Failed"));
return;
}
FStringAssetReference itemRef("/Game/Content/PAK/2_2.2_2");
TSet<FString> FileList;
pakFile.FindFilesAtPath(FileList, *pakFile.GetMountPoint(), true, false, true);
for (auto item : FileList)
{
if (item.EndsWith(FPackageName::GetAssetPackageExtension()) ||
item.EndsWith(FPackageName::GetMapPackageExtension()))
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Cyan, FString::Printf(TEXT("PakFile Assert: %s "), *item));
}
}
FStreamableManager *streamableMgr = new FStreamableManager();
auto temp_matrial_test1 = streamableMgr->SynchronousLoad(itemRef);
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, FString::Printf(TEXT("Try Convert Object to UMaterial : %s "), temp_matrial_test1 != nullptr ? TEXT("True") : TEXT("False")));
streamableMgr->RequestAsyncLoad(itemRef, FStreamableDelegate::CreateLambda([&]()
{
auto temp_matrial_test = StaticLoadObject(UMaterial::StaticClass(), NULL, TEXT("/Game/Content/PAK/2_2.2_2"));
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::Printf(TEXT("Try Convert Object to UMaterial : %s "), temp_matrial_test != nullptr ? TEXT("True") : TEXT("False")));
}));
}