using System.Runtime.InteropServices; using UnityEngine; public class SizeTest : MonoBehaviour { [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct TestStruct { public int intValue; public float floatValue; [MarshalAs(UnmanagedType.U1)] public bool byteValue; } [ContextMenu("Test Size")] void TestSize() { TestStruct q = new(); var size = Marshal.SizeOf(typeof(TestStruct)); // byte[] data = new byte[Marshal.SizeOf(typeof(TestStruct))]; // q = Marshal.PtrToStructure(); Debug.Log("Size of TestStruct: " + size); } }