Assert fails when serializing ULandscapeHeightfieldCollisionComponent for PIE

In FUObjectAnnotationSparseSearchable::AddAnnotation(), checkSlow(NumExistingRemoved == 0) fails with the following (partial) callstack when serializing a landscape heighfield collision component for play-in-editor:

UE4Editor-CoreUObject-Win64-Debug.dll!FUObjectAnnotationSparseSearchable<FUniqueObjectGuid,1>::AddAnnotation(const UObjectBase * Object, FUniqueObjectGuid Annotation) Line 303	C++
 	UE4Editor-CoreUObject-Win64-Debug.dll!FLazyObjectPtr::PossiblySerializeObjectGuid(UObject * Object, FArchive & Ar) Line 142	C++
 	UE4Editor-CoreUObject-Win64-Debug.dll!UObject::Serialize(FArchive & Ar) Line 958	C++
 	UE4Editor-Engine-Win64-Debug.dll!UActorComponent::Serialize(FArchive & Ar) Line 1627	C++
 	UE4Editor-Engine-Win64-Debug.dll!USceneComponent::Serialize(FArchive & Ar) Line 1812	C++
 	UE4Editor-Engine-Win64-Debug.dll!UPrimitiveComponent::Serialize(FArchive & Ar) Line 586	C++
 	UE4Editor-Landscape-Win64-Debug.dll!ULandscapeHeightfieldCollisionComponent::Serialize(FArchive & Ar) Line 1247	C++

This can be reproduced by loading the attached map LandscapeHolesReduced in a debug configuration, then selecting “Play In Active Viewport.”

The problem is that the GUID serialized to the archive isn’t actually assigned to the duplicated object, and thus doesn’t match later on. I fixed this by changing the following line in FLazyObjectPtr::PossiblySerializeObjectGuid() from this:

Guid = FoundGuid = FGuid::NewGuid();

to this:

FUniqueObjectGuid ObjectGuid = FUniqueObjectGuid::GetOrCreateIDForObject(Object);
Guid = FoundGuid = ObjectGuid.GetGuid();

But it would be nice to have official word as to whether this is the right fix.

Hello tim.condon,

As this is a specific piece of code and an official fix requires that the code not cause any problems in any other parts of the engine, Answerhub wouldn’t be the best place to determine that. It would be best if you were able to submit a pull request on Github so that one of the developers that focus in this particular part of the engine can take a look at it and determine if it should be added or explain why it shouldn’t.