Search Unity

When you use C#, you must explicitly derive from MonoBehaviour!

Discussion in 'General Discussion' started by andyz, Jun 20, 2019.

  1. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,276
    Many beginners seem to think that all code must be monobehaviour derived classes in Unity
    Actually you are probably best writing most of your code in straight C# classes as you would anywhere else.
    But I noticed this help text may not be helping!:

    "MonoBehaviour is the base class from which every Unity script derives.
    When you use C#, you must explicitly derive from MonoBehaviour."

    https://docs.unity3d.com/ScriptReference/MonoBehaviour.html

    something to change?!
     
    Amon, Socrates, Ryiah and 4 others like this.
  2. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    Tell that to the ScriptableObject.
     
    xVergilx likes this.
  3. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    That's andyz's point. I agree; it's confusing. If you post this in the Documentation section, they may clarify it.
     
    xVergilx and angrypenguin like this.
  4. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    And that's my point, that I agree with Andyz's point. Instead of being funny and unhelpful, my response was unfunny and unhelpful. :rolleyes:
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    No, I can be a bit dense at times. :)
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Its old wording from the UnityScript days. UnityScript implicitly derived from monobehaviour, while C# requires explicit derivation. Without the context of UnityScript, it doesn't make any sense written this way.
     
    Mkekala, Amon, xVergilx and 2 others like this.
  7. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,276
    Ah could be. Anyway I sent document feedback