OnDisconnectedFromServer ignores inheritance

Hello, this particular problem made me a headache and i don’t know if that’s a bug or feature.
So what i have is Controller scripts looking like this:

public class BaseController: MonoBehaviour
{

}
public class AController: BaseController
{
  protected virtual void OnDisconnectedFromServer ( NetworkDisconnection info )
  {
    Debug.Log("Disconnected A");
  }
}
public class BController: AController
{
  protected override void OnDisconnectedFromServer ( NetworkDisconnection info )
  {
    Debug.Log("Disconnected B");
  }
}

Now my problem is that when i leave the server, OnDisconnectedFromServer (1 ) is called, but it gets called both on AController and then on BController. I have tried even shadowing or calling other method instead like here but no matter what, i cant get to disable/override the behaviour of AController when i have instance of BController. Am i doing something wrong or is this unity bug?

Thank you very much.

For normal inheritance behavior, you aren’t doing anything wrong.

Unity calls these delegate methods through reflection, not through compile-time code. The following sentence is speculation, but I’d say Unity internally detects both methods through reflection and manually calls them both. You can use “this” and “is” in each method to control which one will actually get called, but it’s ugly :frowning:

public class AController: BaseController
 {
   protected virtual void OnDisconnectedFromServer ( NetworkDisconnection info )
   {
     if(this is BController)
         return;
     Debug.Log("Disconnected A");
   }
 }
 public class BController: AController
 {
   protected override void OnDisconnectedFromServer ( NetworkDisconnection info )
   {
     Debug.Log("Disconnected B");
   }
 }