FVariant is a struct that implements a union of data types, including FVector. When assigning an FVariant an FVector value in engine versions UE 4.27 or earlier, the FVariant will deserialize incorrectly in UE 5.0 and later.

The cause for this is the move to Large World Coordinates, so FVectors which had float components before now have double components. FVariant's serialization does not account for this, since it serializes its underlying data as a byte array and for FVectors interprets the old 12 byte (float float float) data as 24 byte (double double double). This results in local data corruption: FVariants that store FVectors in SaveGames and possibly other serialization areas are deserialized with changed values, though the changed data has no direct effect on stability.

For the time being, users can fix-up deserialized FVariants, for example in their SaveGame::Serialize like this:

// Here MyVariant is (and must be) an FVariant storing an FVector value and serialized in UE 4.27 or earlier.
const uint8* BinaryDataAddress = MyVariant.GetBytes().GetData();
const FVector3f OldVector = *reinterpret_cast<const FVector3f*>(BinaryDataAddress);
const FVector NewVector = FVector(OldVector);
MyVariant = NewVector; 

However, for future engine versions it would be better if the fix-up of pre-UE5 FVariants happens automatically.

Steps to Reproduce

New project repro steps:

  • Create a SaveGame class with an FVariant in UE 4.27
  • Override the SaveGame class's Serialize() to also serialize the FVariant via << operator
  • Assign the FVariant an FVector value such as (X=123 Y=456 Z=789)
  • Save the SaveGame to a slot
  • Update the project to UE 5.3
  • Load the SaveGame from the slot
  • Inspect the FVector value
    • Observe: the value has changed to (X=11529217346828763136.000 Y=0.000 Z=0.000)
    • Expected: the valus should still be (X=123 Y=456 Z=789)

UE 4.27 repro project available.

Have Comments or More Details?

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

Login to Vote

ComponentUE - Gameplay - LWC
Affects Versions5.
Target Fix5.5
CreatedJan 15, 2024
UpdatedFeb 16, 2024
View Jira Issue