Hi all,
I’m interested in adding some functionality to Unreal Engine as part of an existing project (the project in question is currently on 4.25, however this seems to exist in 5 main as well from my understanding)
I’m noticing some issues when serializing from an old DDC generated before my changes.
For instance, If I wanted to add some additional serialized property for FPositionMeshVertexBuffer
(the changes are genericized, but in essence, I want to add support for a compressed vertex buffer format, and to be able to serialize to/from that format wherever we decide to use it.):
void FPositionVertexBuffer::SerializeMetaData(FArchive& Ar)
{
Ar << Stride << NumVertices;
// Add additional field
if (Ar.LicenseeUE4Ver() >= EUnrealEngineObjectLicenseeUE4Version::VER_USE_NEW_POSITION_VERTEX_BUFFER_OPTION)
{
Ar << bUseNewOption;
}
else
{
// Ideally, we default to using the older behavior if we are loading from an older archive.
bUseNewOption = false;
}
}
According to the Unreal Engine Documentation regarding use of versioned assets
This seems like an appropriate use of using engine versioning, however in practice I can see that when I deserialize from a DDC, the versioning info is not set:
See StaticMesh.cpp#L2720
(in ue5-main
, the code seems unchanged from UE4 as well…)
https://github.com/EpicGames/UnrealEngine/blob/515378597ff5923607e478efe5a0a4f1ca7b0fb8/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp#L2720
When we initialize the base FArchiveState
object we default to the current engine version:
https://github.com/EpicGames/UnrealEngine/blob/515378597ff5923607e478efe5a0a4f1ca7b0fb8/Engine/Source/Runtime/Core/Private/Serialization/Archive.cpp#L72
https://github.com/EpicGames/UnrealEngine/blob/515378597ff5923607e478efe5a0a4f1ca7b0fb8/Engine/Source/Runtime/Core/Private/Serialization/Archive.cpp#L156
https://github.com/EpicGames/UnrealEngine/blob/515378597ff5923607e478efe5a0a4f1ca7b0fb8/Engine/Source/Runtime/Core/Private/UObject/ObjectVersion.cpp#L20
Which causes us to take the top branch and deserialize the boolean that doesn’t exist, which eventually causes a crash as we are no longer aligned with the old data.
I guess my questions are:
-
is this expected behavior? Are DDCs not intended to be versioned like if this data was loaded from a PAK?
-
How can one achieve the expected behavior of the new serialization code “just working”? Its not quite feasible to invalidate the cache if we don’t know the status of its contents.
Thank you!