Hello everyone!
So, from the info I’ve gathered, Unity uses SendMessage to fire Start() and Update() (and other events) in each MonoBehaviour script. And SendMessage isn’t as performant as a direct function call, or a delegate, because of reflection and stuff.
So, for that reason, and for having easily more control in all my scripts (like calling Update every other frame instead of every frame or something like that), I’ve been experimenting with implementing my own events. This is what I’ve done:
public class TimingClass : MonoBehaviour
{
public event System.Action OnUpdate;
void Update()
{
if (OnUpdate != null) OnUpdate();
}
}
This class uses Unity’s Update() event to fire my own event called OnUpdate().
public class BaseClass : MonoBehaviour
{
TimingClass Timing;
void Start()
{
Timing = GameObject.FindGameObjectWithTag("Timing").GetComponent<TimingClass>();
Timing.OnUpdate += OnUpdate;
}
protected virtual void OnUpdate() { }
void OnDestroy()
{
Timing.OnUpdate -= OnUpdate;
}
}
Then this is my BaseClass that will be the parent of all my scripts.
public class MyObject : BaseClass
{
public float Speed = 50.0f;
protected override void OnUpdate()
{
transform.Rotate(Time.deltaTime * Speed, 0, 0);
}
}
And this is a script that inherits from BaseClass and rotates the GameObject with my own OnUpdate event.
It works ok. In fact, it works really great. I instanced like 500 rotating cubes with this MyObject script and it performs better than with Unity’s Update(). ~1ms with Update(), and ~0.45ms with my own OnUpdate().
However it’s harder to Deep Profile my scripts because of this mess: 
As you can see, if you have many objects, it would be hard to find that sneaky script that is always giving problems. Is there a way for the profiler to show the information in a nicer way in this case?
And what do you think of this event system? Could it give any problems or not be recommended for any possible reason?
Thanks for your attention! ![]()


