# Overridable functions

**URL:** https://discussions.unity.com/t/overridable-functions/397292
**Category:** Scripting
**Tags:** Scripting
**Created:** [August 30, 2009, 11:48pm UTC](https://discussions.unity.com/t/overridable-functions/397292 "2009-08-30T23:48:06Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_4681782](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@anon\_4681782](https://discussions.unity.com/u/anon_4681782)
#### Post date: [August 30, 2009, 11:48pm UTC](https://discussions.unity.com/t/overridable-functions/397292/1 "2009-08-30T23:48:06Z")

</div>

Why Update or Start functions in C# class scripts that are chidren of MonoBehaviour ( of course) can’t be overrided (keyword override C#), when the functions are declared as overridable?  
Is it automatically overided like in C++ when you declare/implement a function that is overridable?

---

<div class="post-metadata">

### Author: ![Ashkan\_gc](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Ashkan\_gc](https://discussions.unity.com/u/Ashkan_gc)
#### Post date: [August 31, 2009, 4:48am UTC](https://discussions.unity.com/t/overridable-functions/397292/2 "2009-08-31T04:48:04Z")

</div>

hi  
there is a really good book about C# for programmers “programming C# 3” by jessie liberty publisher: oreilly

this is implicitly done in unity. i am not sure but i

---

<div class="post-metadata">

### Author: ![tomvds](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tomvds](https://discussions.unity.com/u/tomvds)
#### Post date: [August 31, 2009, 9:04am UTC](https://discussions.unity.com/t/overridable-functions/397292/3 "2009-08-31T09:04:36Z")

</div>

> [@Andre Gregoire](#):
>
> Why Update or Start functions in C# class scripts that are chidren of MonoBehaviour ( of course) can’t be overrided (keyword override C#), when the functions are declared as overridable?  
> Is it automatically overided like in C++ when you declare/implement a function that is overridable?

Unity doesn’t use virtual functions to implement the callback system for MonoBehaviours. It uses reflection to see which functions are implemented and will only perform callbacks on those functions it can find.

This is also why your Start function gets called even if it is defined as private.

---

<div class="post-metadata">

### Author: ![anon\_82884793](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@anon\_82884793](https://discussions.unity.com/u/anon_82884793)
#### Post date: [August 31, 2009, 10:08am UTC](https://discussions.unity.com/t/overridable-functions/397292/4 "2009-08-31T10:08:49Z")

</div>

if you still do want to have such behaviour (which I would expect too btw) in your scripts you could achieve this prety easily with a little level of indirection in your scripts. something along those lines :

```auto
				public class VirtualBehaviour : MonoBehaviour {
					
					void Update(){
						doUpdate();
					}
					protected virtual void DoUpdate(){}
					
					void Wake(){
						DoWake();
					}
					protected virtual void DoWake(){}
					
					void Start(){
						DoStart();
					}
					protected virtual void DoStart(){}
				}

```

---

<div class="post-metadata">

### Author: ![tomvds](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tomvds](https://discussions.unity.com/u/tomvds)
#### Post date: [August 31, 2009, 12:16pm UTC](https://discussions.unity.com/t/overridable-functions/397292/5 "2009-08-31T12:16:11Z")

</div>

> [@""](#):
>
> if you still do want to have such behaviour (which I would expect too btw) in your scripts you could achieve this prety easily with a little level of indirection in your scripts.

The reason Unity uses reflection over virtual functions, is that with the latter it has to call Update, LateUpdate, FixedUpdate and all the other callback on every single MonoBehaviour every frame (or at whatever frequency the function is supposed to be called). For large projects with large numbers of objects, that may result in significant performance overhead as most MonoBehaviours don’t need every possible callback. In fact, in most scripts I write don’t implement more than 3 or 4 of the close to 50 possible MonoBehaviour callbacks.

I wouldn’t recommend working against Unity by forcing everything to be virtual. There is no advantage to doing that, only drawbacks.

---

<div class="post-metadata">

### Author: ![anon\_82884793](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@anon\_82884793](https://discussions.unity.com/u/anon_82884793)
#### Post date: [August 31, 2009, 1:27pm UTC](https://discussions.unity.com/t/overridable-functions/397292/6 "2009-08-31T13:27:48Z")

</div>

thanks for the insight. I didn’t know what was unity’s reason to use reflexion. It’s good to know.

---

<div class="post-metadata">

### Author: ![anon\_4681782](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@anon\_4681782](https://discussions.unity.com/u/anon_4681782)
#### Post date: [August 31, 2009, 7:55pm UTC](https://discussions.unity.com/t/overridable-functions/397292/7 "2009-08-31T19:55:42Z")

</div>

Thx alot guys, it’s good to understand the mechanics!
