// validation for the data: // This is important if the player loaded the savegame without the mod for a while public void AfterDeserialize(DataSerializer s) { // Remove invalid segment data var removedSegmentCount = 0; for (ushort i = 0; i < SegmentSkins.Length; i++) { if (SegmentSkins[i] == null) { continue; } if (!NetManager.IsSegmentCreated(i)) { SegmentSkins[i] = null; removedSegmentCount++; continue; } var segmentPrefab = NetManager.GetSegmentInfo(i); if (segmentPrefab != SegmentSkins[i].Prefab) { SegmentSkins[i] = null; removedSegmentCount++; continue; } SegmentSkins[i].UseCount++; } // remove invalid node data var removedNodeCount = 0; for (ushort i = 0; i < NodeSkins.Length; i++) { if (NodeSkins[i] == null) { continue; } if (!NetManager.IsNodeCreated(i)) { NodeSkins[i] = null; removedNodeCount++; continue; } var nodePrefab = NetManager.GetNodeInfo(i); if (nodePrefab != NodeSkins[i].Prefab) { NodeSkins[i] = null; removedNodeCount++; continue; } NodeSkins[i].UseCount++; } // remove unused and invalid skins var removedSkinCount = 0; for (var i = AppliedSkins.Count - 1; i >= 0; i--) { if (AppliedSkins[i] == null || AppliedSkins[i].UseCount <= 0) { AppliedSkins[i]?.Destroy(); AppliedSkins.RemoveAt(i); removedSkinCount++; } } Debug.Log($"NS: Savegame data validation succesful! {removedSegmentCount} | {removedNodeCount} | {removedSkinCount}"); Debug.Log($"NS: {AppliedSkins.Count} applied skins"); }