Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug MonoBehaviour inheritance completely broken

Discussion in '2020.2 Beta' started by Aezoc, Sep 19, 2020.

  1. Aezoc

    Aezoc

    Joined:
    Jan 19, 2020
    Posts:
    8
    if I create class A : MonoBehaviour and class B : A, I cannot attach B to a GameObject in 2020.2b2. B does not appear in the list when clicking Add Component, and drag/dropping the script onto a GameObject shows "The script don't inherit a native class that can manage a script."

    This approach works completely fine in 2020.1.5f1 and earlier versions. I also upgraded an existing project that makes use of MonoBehaviour inheritance, and the behavior in my game is now very buggy. If A has virtual void Start() and B has an override that calls base.Start(), then component B will start receiving Update()s as soon as base.Start() completes (but before B's Start() does), which breaks all kinds of things.
     
  2. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    265
    I'm unable to reproduce this with 2020.2.0b2.

    A.cs:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class A : MonoBehaviour
    4. {
    5.     public virtual void Start()
    6.     {
    7.         Debug.Log("A::Start", this);
    8.     }
    9. }
    B.cs:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class B : A
    4. {
    5.     public override void Start()
    6.     {
    7.         base.Start();
    8.         Debug.Log("B::Start", this);
    9.     }
    10.  
    11.     void Update()
    12.     {
    13.         Debug.Log("B::Update", this);
    14.     }
    15. }
    I get this output:
    Code (csharp):
    1. A::Start
    2. B::Start
    3. B::Update
    4. B::Update
    5. B::Update
    6. ...
     
    Peter77 likes this.
  3. Aezoc

    Aezoc

    Joined:
    Jan 19, 2020
    Posts:
    8
    The test case posted above is almost identical to what I was using, and also didn't work for me. However after a reboot the problem is gone and both test cases as well as my original project are working as expected again.

    ¯\_(ツ)_/¯