x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

SaveGameToSlot and/or LoadGameFromSlot not working. Why?

After a lot of frustrating failures in my project, I created a small project to test saving and loading. In the player controller's BeginPlay I have this:

     UTestSaveGame* NewSave = Cast<UTestSaveGame>(UGameplayStatics::CreateSaveGameObject(UTestSaveGame::StaticClass()));
     NewSave->TestString = "Save me!";
     NewSave->TestInt = 42;
     UGameplayStatics::SaveGameToSlot(NewSave, "Slot1", 1);
     UE_LOG(LogTemp, Log, TEXT("TestString:  %s"), *NewSave->TestString);
     UE_LOG(LogTemp, Log, TEXT("TestInt:  %d"), NewSave->TestInt);

Then I call this:

 void ATestPlayerController::TryLoading()
 {
     UTestSaveGame* ReloadedSave = Cast<UTestSaveGame>(UGameplayStatics::CreateSaveGameObject(UTestSaveGame::StaticClass()));
     ReloadedSave = Cast<UTestSaveGame>(UGameplayStatics::LoadGameFromSlot("Slot1", 1));
     UE_LOG(LogTemp, Log, TEXT("TestString:  %s"), *ReloadedSave->TestString);
     UE_LOG(LogTemp, Log, TEXT("TestInt:  %d"), ReloadedSave->TestInt);
 }

Here are the pertinent lines from the log:

 [2018.11.12-07.43.16:971][  0]LogTemp: TestString:  Save me!
 [2018.11.12-07.43.16:973][  0]LogTemp: TestInt:  42
 [2018.11.12-07.43.20:432][206]LogTemp: TestString:
 [2018.11.12-07.43.20:432][206]LogTemp: TestInt:  0

I create a new instance of a custom SaveGame, I set a couple class variables, and save. Then I load up an instance of it, and the information is gone. What's going on?

Product Version: UE 4.20
Tags:
more ▼

asked Nov 12 '18 at 07:45 AM in C++ Programming

avatar image

Merrick
6 3 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Turns out I had to declare the variables in question with

  UPROPERTY(VisibleAnywhere, Category = Basic)

more ▼

answered Nov 12 '18 at 04:36 PM

avatar image

Merrick
6 3 3

avatar image Blindopoly Mar 20 '19 at 02:31 AM

Thanks for your reply! You actually only need UPROPERTY() by the way.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question