Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Hides inherited member UIBehaviour.Start()?

Discussion in 'Scripting' started by MikeUpchat, Jul 28, 2016.

  1. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,055
    I am trying to do a custom mesh for some UI code and I have a simple class derived from UI.Graphic and in there I have a Start() method but I get a warning:

    I tried doing private override Start() and new Start() what is the correct way to get rid of this warning? I look at all the various examples for derived classes in Unity example code and they just have void Start() so a bit confused.

    Code (csharp):
    1.  
    2. public class MyCircleGraph : Graphic
    3. {
    4.     public Mesh mesh;
    5.  
    6.     void Start()
    7.     {
    8.         mesh = new Mesh();
    9.     }
    10. }
    11.  
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Code (csharp):
    1.  
    2. protected override void Start()
    3. {
    4.      base.Start();  // make sure base init stuff gets done
    5. }
    6.  
     
    gigazelle likes this.
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,181
    Before you ask; that requires Start in the base class to be declared as protected virtual, otherwise you'll get a compilation error.
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,181
    It actually is! Sorry, my bad, didn't see that it was a non-monobehaviour.
     
    KelsoMRK likes this.
  6. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    I do appreciate the fact that with the new UI and Networking stuff that they're doing a lot more virtual methods and less magic string stuff.