Why are Start, Update and Destroy private?

This is something which has been bothering me for some time. In Unity’s C# all scripts which have Update/Destroy functions have them set to private implicitly. Does unity ‘cheat’ to call these functions?

Also would it be ok to make them virtual or could that present problems later down the line?

1 Answer

1

It works because of inheriting from MonoBehaviour. MonoBehaviours have code in them (that you can’t see) that enables all of that. It’s not quite “cheating” as you call it, but it’s the next best thing. I assume it works in a similar manner to Component.SendMessage- except without all that messy runtime string parsing. As for making them virtual- I wouldn’t mess with that. It’s probably not necessary, and could probably screw things up (although I’m not actually sure about that one). Try it out- see what it does! Make sure you have tested it thoroughly before committing to doing something that risky, though.