Skip to content

Commit

Permalink
Add note about unity
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Mar 21, 2024
1 parent ce4c03a commit 328bb5e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1339,8 +1339,7 @@ For more information on Unity and Source Generator, please refer to the [Unity d

Source Generator is also used officially by Unity by [com.unity.properties](https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/index.html) and [com.unity.entities](https://docs.unity3d.com/Packages/com.unity.properties@2.0/changelog/CHANGELOG.html). In other words, it is the standard for code generation in the next generation of Unity.

> [!WARNING]
> Unity version does not support CustomFormatter.
When interoperating with MemoryPack in Unity and .NET, the simple solution is to avoid these types.

You can serialize all unmanaged types (such as `Vector3`, `Rect`, etc...) and some classes(`AnimationCurve`, `Gradient`, `RectOffset`). If you want to serialize other Unity-specific types, see [Serialize external types](#serialize-external-types) section.

Expand All @@ -1352,6 +1351,19 @@ If shared code has Unity's type(`Vector2`, etc...), MemoryPack provides `MemoryP

The `MemoryPack.UnityShims` package provides shims for Unity's standard structs (`Vector2`, `Vector3`, `Vector4`, `Quaternion`, `Color`, `Bounds`, `Rect`, `Keyframe`, `WrapMode`, `Matrix4x4`, `GradientColorKey`, `GradientAlphaKey`, `GradientMode`, `Color32`, `LayerMask`, `Vector2Int`, `Vector3Int`, `RangeInt`, `RectInt`, `BoundsInt`) and some classes(`AnimationCurve`, `Gradient`, `RectOffset`).

> [!WARNING]
> Currently, the following limitations exist for use in Unity

1. Unity version does not support CustomFormatter.
2. If you are using .NET7 or later, MemoryPack binary format is not fully compatible with Unity.
- This problem occurs with value types that `[StructLayout(LayoutKind.Auto)]` is explicitly specified. (The default for struct is `LayoutKind.Sequencil`.) For such types, binaries serialized in .NET cannot be deserialized in Untiy. Similarly, a binary serialized in Unity cannot be serialized in .NET side.
- The affected types typically include the following types.
- `DateTimeOffset`
- `ValueTuple`
- Currently, the simple solution is to not use these types.


Native AOT
---
Unfortunately, .NET 7 Native AOT causes crash (`Generic virtual method pointer lookup failure`) when use MemoryPack due to a runtime bug. It
Expand Down

0 comments on commit 328bb5e

Please sign in to comment.