Remove Empty Unity Events - Do Empty Unity Events cause Performance Issues?

      You definitely have noticed this thing that whenever you create a new script in Unity3D, the Unity scripting template adds two methods or unity events by default. The two methods are Start () &Update ().
using UnityEngine;
using System.Collections;

public class MyCustomScript : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
The good thing about the default script template is that you can edit it and you can find Unity Script template file at this location %EDITOR_PATH%\Data\Resources\ScriptTemplates
where EDITOR_PATH is the actual unity installation location in your PC (see below video). You can edit this script template according to your requirements.
A common question asked by most of the unity developers or users that Do Empty Unity events (e.g., start, update or awake etc) create any performance issue? The simple answer is YES! After watching the optimization video of Unity 2020 I can confirm this thing to you.  Actually, the Empty events incur a small overhead. If you have less scripts with empty unity events then maybe it will not make any significant difference but as your project grows and you have Hundred or thousand of empty unity events then, certainly it will cost you some of the performance issue. So, the best practice is to remove those events when you don't require. And if you required those events for specific platform like for testing purposes you can use unity platform dependent compilation like this:
#if UNITY_EDITOR
void Update(){

}
#endif
Now, the Update()code block will only run in the editor and it will not work or compile in the final build. Or you can edit the default scripting template file according to your needs which I have mentioned in the above video.  

No comments:

Post a Comment