What could be causing this crash with TMap FindRef?

What causes this to crash?

AVAbility* UVAbilitySystemComponent::GetOrSpawnAbility(TSubclassOf<class AVAbility> AbilityClass)
{
	TMap<TSubclassOf<class AVAbility>, AVAbility*> debug;
	if ( IsValid( AbilityClass ) )
	{
		debug.FindRef( AbilityClass ); //Doesn't crash
		**SpawnedAbilities.FindRef( AbilityClass );** //Crashes
        }
        return nullptr;
}

GetOrSpawnAbility is called in BeginPlay of an ActorComponent.
The crash happens with SpawnedAbilities.FindRef( AbilityClass ). SpawnedAbilities is declared in the header of the component:
UPROPERTY(EditInstanceOnly, SaveGame, Instanced)
TMap<TSubclassOf, AVAbility*> SpawnedAbilities;

More specifically it crashes in FindId in Set.h. Line marked with **.
Exception thrown at 0x00007FFC73136D53 (UnrealEditor-TBC-Win64-DebugGame.dll) in UnrealEditor-Win64-DebugGame.exe: 0xC0000005: Access violation reading location 0x00000A5F86246048.

FSetElementId FindId(KeyInitType Key) const
	{
		if (Elements.Num())
		{
			**for(FSetElementId ElementId = GetTypedHash(KeyFuncs::GetKeyHash(Key));**
				ElementId.IsValidId();
				ElementId = Elements[ElementId].HashNextId)
			{
				if(KeyFuncs::Matches(KeyFuncs::GetSetKey(Elements[ElementId].Value),Key))
				{
					// Return the first match, regardless of whether the set has multiple matches for the key or not.
					return ElementId;
				}
			}
		}
		return FSetElementId();
	}

The crash only happens after I load the game from a save with my own deserialization so I think I could be doing something wrong there, but I’m not sure what to look for. All the related objects return true for IsValid().

1 Like