Need help with AsyncLoadGameFromSlot using custom savegame [C++]

Thank you if you take the time to respond!

So the Unreal Documentation has this about async loading. Here’s a link to the full doc: Saving and Loading Your Game C++

	// Set up the delegate.
	FAsyncLoadGameFromSlotDelegate LoadedDelegate;
	// USomeUObjectClass::LoadGameDelegateFunction is a void function that takes the following parameters: const FString& SlotName, const int32 UserIndex, USaveGame* LoadedGameData
	LoadedDelegate.BindUObject(SomeUObjectPointer, &USomeUObjectClass::LoadGameDelegateFunction);
	UGameplayStatics::AsyncLoadGameFromSlot(SlotName, 0, LoadedDelegate);

However, I haven’t a clue what USomeUObjectClassor or &USomeUObjectClass are supposed to be. I’ve looked at the implementation within the engine and that hasn’t helped me either. Below is what I’ve gotten so far, but I wouldn’t be surprised if I’m completely off base.

if(Async)
		{
			// set up the delegate
			FAsyncLoadGameFromSlotDelegate LoadedDelegate;
			// USomeUObjectClass::LoadGameDelegateFunction is a void function that takes the following parameters: const FString& SlotName, const int32 UserIndex, USaveGame* LoadedGameData
			LoadedDelegate.BindUObject(SaveGameReference, &USomeUObjectClass::LoadGameDelegateFunction(TempSlotName, TempUserIndex, SaveGameReference));
			
			UGameplayStatics::AsyncLoadGameFromSlot(TempSlotName, TempUserIndex,LoadedDelegate);
			UE_LOG(LogTemp, Display, TEXT("Game Loaded, Async true"));
			GameLoaded.Broadcast(SaveGameReference);
		}

SomeUObjectPointer可以是外部传进来的,比如调用的地方,也可以是当前类:

void UMySaveGame::AsyncSave()
{
	if (UMySaveGame* SaveGameInstance = Cast<UMySaveGame>(UGameplayStatics::CreateSaveGameObject(UMySaveGame::StaticClass())))
	{
		FAsyncSaveGameToSlotDelegate SavedDelegate;
		SavedDelegate.BindUObject(this, &UMySaveGame::ProcessSaveComplete);
		SaveGameInstance->PlayerName = TEXT("PlayerOne");
		UGameplayStatics::AsyncSaveGameToSlot(SaveGameInstance, SaveSlotName, UserIndex, SavedDelegate);
	}
}

void UMySaveGame::ProcessSaveComplete(const FString& SlotName, const int32 Index, bool bSuccess)
{
	if (bSuccess)
	{
		// 保存成功
	}
}
1 Like

Thank you for this, you’re such a legend