Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


allowUnsafeCode

Allow unsafe C# code to be compiled for predefined assemblies.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Property
  • Namespace: UnityEditor
  • Assembly: UnityEditor
public static bool allowUnsafeCode { get; set; }

Remarks

Enable to pass
/unsafe
to the C# compiler when compiling predefined assemblies, such as
Assembly-CSharp.dll
. This setting only affects code that isn't compiled into separate assemblies via
.asmdef
files.
Enable this only if your project requires direct pointer manipulation for extreme performance or native C++ interoperability. For general high-performance data handling, consider using
Unity.Collections
or
System.Span<T>
first.
Warning: Code compiled with
/unsafe
flag can bypass the .NET runtime's memory safety. An invalid memory access typically crashes the application or the Editor without a stack trace.
Note: For
.asmdef
assemblies, enable the Allow 'unsafe' Code checkbox in the Assembly Definition Inspector instead.