Skip to content

Commit e45cedb

Browse files
committed
Fix serialization #if to check for Unity 2020+
Generic classes are only serialized in Unity 2020+, so it makes no sense having serialization fields in previous versions.
1 parent b6b0469 commit e45cedb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Runtime/EnumBitSet.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using Gilzoide.NamedEnum;
5-
#if UNITY_5_3_OR_NEWER
5+
#if UNITY_2020_1_OR_NEWER
66
using UnityEngine;
77
#endif
88

@@ -11,7 +11,7 @@ namespace Gilzoide.EnumBitSet
1111
[Serializable]
1212
public class EnumBitSet<T, TData> : ISet<T>
1313
, IReadOnlySet<T>
14-
#if UNITY_5_3_OR_NEWER
14+
#if UNITY_2020_1_OR_NEWER
1515
, ISerializationCallbackReceiver
1616
#endif
1717
where T : struct, Enum
@@ -172,14 +172,18 @@ IEnumerator IEnumerable.GetEnumerator()
172172

173173
#endregion
174174

175-
#if UNITY_5_3_OR_NEWER
175+
#if UNITY_2020_1_OR_NEWER
176176
#region ISerializationCallbackReceiver
177177

178178
[SerializeField] private NamedEnum<T>[] _serializedEnums;
179179

180180
public void OnAfterDeserialize()
181181
{
182182
Clear();
183+
if (_serializedEnums == null)
184+
{
185+
return;
186+
}
183187
foreach (NamedEnum<T> serializedValue in _serializedEnums)
184188
{
185189
Add(serializedValue);

0 commit comments

Comments
 (0)