Unity optimizations
Unity Optimizations in Project Settings → ZLua is on by default. Today it only covers GetComponent on GameObject / Component.
Why optimize it
GetComponent is the hottest Unity call from scripts. The default binding has two costs on that path:
- Three overloads share the short name
GetComponent(generic,Type, andstring). Every call goes through overload dispatch, and the generic form also needsinflate/ GTAP. - The return view is the declared type (often
Componentor an interface). When the instance is actually aButton, Lua cannot seeonClickuntil youzlua.cast.
With the switch on, the generic and string overloads get their own short names and no longer compete with GetComponent(Type); the return view is the actual type.
If you leave it off
Unchecking restores the behavior from before this optimization:
- All three overloads stay named
GetComponentand go through overload dispatch. - The return view stays the type you asked for; derived members need
zlua.cast.
Names when enabled
With it on, the three overloads map to these Lua names (GetComponent(Type) keeps its name):
| C# | Lua when enabled |
|---|---|
GetComponent<T>() | go:GetComponentT(zlua.typeof(Button)) |
GetComponent(Type) | go:GetComponent(typeObject) |
GetComponent(string) | go:GetComponentN("UnityEngine.UI.Button") |
The return value uses the component’s actual type. Fetching through an interface or base type still exposes derived fields (for example Button.onClick).
Field list: Settings. Call details and limits: Unity optimizations (guide).