IL2CPP 스크립팅 백엔드를 사용하는 경우 IL2CPP.exe 가 C++ 코드를 생성하는 방법을 설정할 수 있습니다. 특히 C# 속성을 사용하여 아래에 나열된 다음 런타임 체크를 활성화하거나 비활성화할 수 있습니다.
| 옵션 | 설명 | **기본값** |
|:—|:—|:—|
|Null checks_ | 이 옵션을 활성화하면 IL2CPP에 의해 생성된 C++ 코드가 null 체크를 포함하고 필요한 경우 관리된 NullReferenceException 예외를 발생시킵니다. 이 옵션을 비활성화하면 생성된 null 체크를 C++ 코드로 내보내지 않습니다. 일부 프로젝트에서 이 옵션을 비활성화하면 런타임 성능이 향상될 수 있습니다.
하지만 생성한 코드는 null 값에 대한 액세스를 보호하지 않아 잘못된 동작을 일으킬 수 있습니다. 일반적으로 null 값이 참조된 후에는 게임 작동이 곧 중단되지만, 보장할 수는 없습니다. 이 옵션을 비활성화하려면 신중히 결정합니다. | 활성화 |
|Array bounds checks | 이 옵션을 활성화하면 IL2CPP에 의해 생성된 C++ 코드가 배열 바운드 체크를 포함하고 필요한 경우 매니지드 IndexOutOfRangeException 예외를 발생시킵니다. 이 옵션을 비활성화하면 배열 바운드 체크를 생성된 C++ 코드로 내보내지 않습니다.
일부 프로젝트에서 이 옵션을 비활성화하면 런타임 성능이 향상될 수 있습니다. 하지만 생성한 코드는 배열에 대해 유효하지 않은 인덱스로의 액세스를 보호하지 않아 임의 위치에 메모리를 쓰거나 읽는 등의 잘못된 동작이 발생할 수 있습니다. 대부분의 경우 이런 메모리 액세스는 즉각적인 부작용 없이 발생하고 게임 상태를 은밀하게 손상시킬 수 있습니다. 이 옵션을 비활성화하려면 매우 신중히 결정합니다. | 활성화 |
|Divide by zero checks | 이 옵션을 활성화하면 IL2CPP에 의해 생성된 C++ 코드가 정수 나눗셈 항목에 0으로 나누기 체크를 포함하고 필요한 경우 매니지드 DivideByZeroException 예외를 발생시킵니다. 이 옵션을 비활성화하면 정수 나눗셈 항목의 0으로 나누기 체크를 생성된 C++ 코드로 내보내지 않습니다. 이 옵션은 대부분의 프로젝트에서 비활성화해야 합니다. 0으로 나누기 체크를 실행하면 많은 런타임이 소모되므로 필요한 경우에만 활성화합니다. | 비활성화 |
런타임 체크는 C# 코드에서 Il2CppSetOptions
속성을 사용하여 활성화하거나 비활성화할 수 있습니다. 이 속성을 사용하려면 컴퓨터에 설치된 Unity 에디터의 IL2CPP 디렉토리(Windows는 Data\il2cpp, OS X는 Contents/il2cpp)에서 Il2CppSetOptionAttribute.cs 파일을 찾으십시오. 이 파일을 프로젝트의 Assets 폴더로 복사합니다.
이제 속성을 아래 예제와 같이 사용합니다.
[Il2CppSetOption(Option.NullChecks, false)]
public static string MethodWithNullChecksDisabled()
{
var tmp = new object();
return tmp.ToString();
}
Il2CppSetOptions
속성을 타입, 메서드 및 프로퍼티에 적용할 수 있습니다. Unity는 대부분 로컬 스코프에서 속성을 사용합니다.
[Il2CppSetOption(Option.NullChecks, false)]
public class TypeWithNullChecksDisabled
{
public static string AnyMethod()
{
// Null checks will be disabled in this method.
var tmp = new object();
return tmp.ToString();
}
[Il2CppSetOption(Option.NullChecks, true)]
public static string MethodWithNullChecksEnabled()
{
// Null checks will be enabled in this method.
var tmp = new object();
return tmp.ToString();
}
}
public class SomeType
{
[Il2CppSetOption(Option.NullChecks, false)]
public string PropertyWithNullChecksDisabled
{
get
{
// Null checks will be disabled here.
var tmp = new object();
return tmp.ToString();
}
set
{
// Null checks will be disabled here.
value.ToString();
}
}
public string PropertyWithNullChecksDisabledOnGetterOnly
{
[Il2CppSetOption(Option.NullChecks, false)]
get
{
// Null checks will be disabled here.
var tmp = new object();
return tmp.ToString();
}
set
{
// Null checks will be enabled here.
value.ToString();
}
}
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.