Search Issue Tracker
Won't Fix
Votes
0
Found in
2021.3.52f1
2022.3.62f1
6000.0.50f1
6000.1.5f1
6000.2.0b3
Issue ID
UUM-107664
Regression
No
UnsafeUtility.AlignOf<T> calculates the alignment of explicitly laid-out structs incorrectly when using structs containing fixed-size buffers or single fields with padding
How to reproduce:
1. Open the “IN-102034_repro“ project
2. In the menu, select Window → General → Test Runner
3. Press Run All
Expected result: All tests pass
Actual result: Two tests fail
Reproducible with: 2021.3.52f1, 2022.3.62f1, 6000.0.50f1, 6000.1.5f1, 6000.2.0b3
Reproducible on: Windows 10, macOS 15.4.1
Not reproducible on: No other environment tested
Notes:
- Reproduces when running the tests in Edit Mode, Play Mode, and Player
- Similar to an existing issue, however, not the same
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
Resolution Note:
The current behavior is correct. Pack is an upper bound on alignment and not a lower bound. If you want 4 byte alignment you can do this:
```[StructLayout(LayoutKind.Explicit, Size=28, Pack=4)]
struct ExplicitPack4FixedArrayByte
{
[FieldOffset(0)] public fixed byte data[28];
[FieldOffset(0)] private int __allign;
}```
but the current behavior of AlignOf reflects the actual C# runtime alignment, which is the definition of correctness here.