Override, as I understand it

Without reading anyone else’s explanations first, I’d like to take a shot at explaining MY understanding of "override."
Override allows you to essentially replace a method that is already inherited into the current class with your own code.
Right?

Correct. also using base.WhateverNetworkFunctionYourOverriding() will run all original code from the function in that single line.

So like… MyStartHost function calls the Override function to StartHost() and our override function is as follows:

public override void StartHost(){
base.StartHost();
Debug.Log(“StartHost Running…”);
}

This runs the original code and everything you add to it, in this case we only added a debug.log message. :wink:

1 Like

Does that work though? I thought NetworkManager’s StartHost is private? Changing the visibility level of an overridden method seemed to be not allowed according to the C# docs.

Second thing to mention is that base is equivalent to super in other languages.

Privacy & Terms