- Home /
undo redo + custom serialization slow
I’m working on an editor for a hexagonal game board. Once a HexBoard is in the scene and selected in the Hierarchy one can place tiles onto the board by clicking the appropriate hexagon in the scene view. HexBoardEditor provides bunch of buttons to select the tile type, handles events and applies the necessary changes to HexBoard when a tile is clicked. This works just fine. I can save/load etc. Undo/Redo though are very slow (1-2s) and dragging across the board completely freezes everything for a few seconds. I’ve made an effort to only call RecordObject when the board will actually change, but it seems to make no difference. I’ve noticed that GameState.OnBeforeSerialize is constantly being called when HexBoard is selected in the hierarchy, but this seems to be something outside my control. I’ve added the relevant code snippets below. I would be grateful for any explanation or advice.
many thanks
[Serializable]
public class GameState : ISerializationCallbackReceiver
{
// WorldState is plain C#
private WorldState<BoardCoordinates, GameResourceBundle> _worldState;
[SerializeField]
private byte[] _serializedState;
public void OnBeforeSerialize()
{
...
bf.Serialize(stream, _worldState);
_serializedState = stream.ToArray();
}
public void OnAfterDeserialize()
{
...
}
}
public class HexBoard : MonoBehaviour
{
[SerializeField]
public GameState HexBoardState;
… views GameState by creating/updating a mesh
}
public HexBoardEditor()
{
private void OnSceneGUI()
{
if (... board object will be changed ...)
{
if (e.type != EventType.MouseDrag)
{
Undo.RecordObject(hexBoard, _editActions[selectedFeatureIndex].Name);
}
hexBoard.SomeMethodThatChangesGameState()
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612100705im_/https://answers.unity.com/themes/thub/images/avi.jpg)