Unity Issue Tracker - UnsafeUtility.AlignOf<T>() reports incorrect value for Explicit layout structs when building with IL2CPP backend
Fixed
UUM-40355
UnsafeUtility.AlignOf<T>() reports incorrect value for Explicit layout structs when building with IL2CPP backend
Unity: IL2CPP
Fixed
2023.2.X
2023.1.X
2022.3.X
Fixed field alignment of generic struct fields in il2cpp
Reproduction steps:
1. Open project “AlignOfBugReport.zip”
2. Enter Play Mode and observe “Align of test struct: 4” text displayed in Game view
3. Build and Run (might need to disable “Create Xcode Project” in the Build Settings first)
4. Observe Player
Expected result: “Align of test struct: 4” text is displayed
Actual result: “Align of test struct: 1” text is displayed
Changing the BugStruct definition from “LayoutKind.Explicit” to “LayoutKind.Sequential" in “AlignOfBug.cs” at line 4, while commenting out [FieldOffset(0)] at line 8 and [FieldOffset(4)] at line 9 gives expected results
Prioritise and Follow this issue
Have a workaround or additional info about this issue?