diff --git a/docs/Classes/SyncVarHook.md b/docs/Classes/SyncVarHook.md index 5cfd15002..55bc15339 100644 --- a/docs/Classes/SyncVarHook.md +++ b/docs/Classes/SyncVarHook.md @@ -23,25 +23,23 @@ public class PlayerController : NetworkBehaviour } [SyncVar(hook = nameof(SetColor))] - public Color playerColor = Color.black; + Color playerColor = Color.black; - // Unity makes a clone of the material when - // GetComponent().material is used. - // Cache it here and Destroy it in OnDestroy - // to prevent a memory leak. - Material materialClone; + // Unity makes a clone of the Material every time GetComponent().material is used. + // Cache it here and Destroy it in OnDestroy to prevent a memory leak. + Material cachedMaterial; void SetColor(Color color) { - if (materialClone == null) - materialClone = GetComponent().material; + if (cachedMaterial == null) + cachedMaterial = GetComponent().material; - materialClone.color = color; + cachedMaterial.color = color; } - private void OnDestroy() + void OnDestroy() { - Destroy(materialClone); + Destroy(cachedMaterial); } } ```