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.
REGRESSION:
No.
RESULT:
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.
EXPECTED:
The warning log messages show a 0 value for each number.
WORK AROUND:
Do not initialize the int array with FMath::RandRange().
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-63448 in the post.
3 |
Component | UE - Gameplay |
---|---|
Affects Versions | 4.19.2, 4.20.2, 4.21 |
Created | Aug 28, 2018 |
---|---|
Resolved | Mar 26, 2019 |
Updated | Mar 27, 2019 |