Search Unity

Inheritance: Same name multiple times included error

Discussion in 'iOS and tvOS' started by Proto, Aug 21, 2010.

  1. Proto

    Proto

    Joined:
    Aug 20, 2007
    Posts:
    79
    I'm getting a console error when I try to override a virtual member in an inherited class.

    Error: Same name multiple times included:::Base(MonoBehaviour) stageObjectType

    StageObject.cs
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. public enum StageObjectType {Player = 0, Ally = 1, EnemyAI = 2, Character = 3, Collectable = 4, Obstacle = 5, Building = 6 }
    5.  
    6. public class StageObject : MonoBehaviour {
    7.     public virtual StageObjectType stageObjectType;
    8. }
    9.  
    Character.cs
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Character : StageObject {
    6.     public override StageObjectType stageObjectType = StageObjectType.Character;
    7. }
    8.  
    Can you see what I'm missing?
     
  2. giyomu

    giyomu

    Joined:
    Oct 6, 2008
    Posts:
    1,094
    why are you using virtual / override on member, i everytime use that keyword on function. ?

    if your base class get that enum as

    public StageObjectType stageObjectType;

    then your inhereted class should see it as well without need to declare it again in your inherited class

    at least this how it work for me , your public variable on your base class will be visible for all your inherited class. i think..
     
  3. Proto

    Proto

    Joined:
    Aug 20, 2007
    Posts:
    79
    Hi giyomu,

    Thanks for your reply. My example may not have been well chosen. I was curious as to how to use a virtual / override and I'm still hoping to get some guidance.

    Using this example without virtual/override, and attempting to assign a new value to the inherited public member actually causes a console parsing error. I can however assign the member a new value as long as I create a constructor function for the subclass and assign the new value there.

    Could anyone suggest a virtual / override syntax?
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    virtual and override is for functions, not fields.

    its a mono 1.2.5 bug that you can even do it, such mess like the one there will lead to compiler errors if you put the code into a non-bugged .net environment (VC#, mono 2.x and unity 3)
     
  5. Proto

    Proto

    Joined:
    Aug 20, 2007
    Posts:
    79
    Ah yes, I was wondering about that thanks Dreamora.
     
  6. justbecrazy

    justbecrazy

    Joined:
    Jun 17, 2011
    Posts:
    6