Developer Notes

This is not a bug, what's going on here is that when a SaveGame is serialized it uses Delta Serialization so only writes out values that differ from the default. In this case the default value changes every time the game is run, so it will skip saving out some values, and then those values will change next time. In UE4 constructors need to be 100% consistent, if you need to do randomization it needs to be a separate function called after the constructor.


After using FMath::RandRange() to initialize elements of an int array in a SaveGame class and then setting all of the values of the array to 0 before using UGameplayStatics::SaveGameToSlot() to save the array to a slot, retrieving the saved values from that slot will almost always result in one or more elements of the array not containing 0. When this happens, the value contained in that element of the array is randomized every time the saved data is loaded. Closing and re-opening the project will result in a different element(s) of the array not containing a 0 value.

If FMath::RandRange() is not used, then all elements of the array will always have a 0 value when the saved data is loaded.


Steps to Reproduce
  1. Download and unzip the attached test project (created in Main CL 4319846).
  2. Right-click the .uproject file and Generate Project Files.
  3. Open the solution in Visual Studio.
  4. Build the project.
  5. Open the project in the Editor.
  6. Make sure the Output Log window is visible.
  7. Start PIE.

A warning log message is printed on Tick that should include 20 integer values that should all be 0. One or more of the numbers will show a non-0 value.

The warning log messages show a 0 value for each number.

Do not initialize the int array with FMath::RandRange().

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-63448 in the post.

Login to Vote

Won't Fix
ComponentUE - Gameplay
Affects Versions4.
CreatedAug 28, 2018
ResolvedMar 26, 2019
UpdatedMar 27, 2019