Inheritance: Same name multiple times included error

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

using UnityEngine;
using System.Collections;
public enum StageObjectType {Player = 0, Ally = 1, EnemyAI = 2, Character = 3, Collectable = 4, Obstacle = 5, Building = 6 }

public class StageObject : MonoBehaviour {
	public virtual StageObjectType stageObjectType;
}

Character.cs

using UnityEngine;
using System.Collections;

public class Character : StageObject {
	public override StageObjectType stageObjectType = StageObjectType.Character;
}

Can you see what I’m missing?

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…

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?

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)

Ah yes, I was wondering about that thanks Dreamora.

But right now it’s here again:
http://answers.unity3d.com/questions/154916/console-error-message-same-name-multiple-time-incl.html