Base, Derived value reference help needed

GObj Player has *QM_BaseActor : MonoBehaviour * and QM_PlayerCharacter : QM_BaseActor


protected float curEnergy;
public float pubCurEnergy { get { return curEnergy; } }

Awake() sets cur/maxEnergy to 10/50 and UI elements mirror those values.

Update() from Base_Actor Debug() shows cur/max values as expected


Update() from QM_PlayerCharacter, Debug() has

	Debug.Log ("PlayerCharacter: pubCurEnergy " + pubCurEnergy + " curEnergy " + curEnergy);

displaying 0/0. Game status checks that have references to QM_PlayerCharacter all return 0 pubCurEnergy (i.e. spellCastingCheck).

QM_PlayerCharacter does not have any fields or properties (curEnergy, maxEnergy, etc) that override Base_Actor.

Derived has access to Base, so please help me understand why PC class returns 0/0 while Base returns correct values? I’m new to inheritance (and honestly starting to regret ever testing the waters…) so this might be something really basic that I’ve done wrong.

If you have Awake() defined on QM_PlayerCharacter, then the Awake() method on QM_BaseActor won’t be called. You should add this line to your Awake() method on QM_PlayerCharacter:


This way it will call Awake on the parent class.

your Player_Character already contains the base so you do not add it.

public class BaseActor:MonoBehaviour{
    protected virtual void Awake(){ //stuff }
public class Player_Character : BaseActor{
   protected override void Awake(){ base.Awake(); }

this is what your classes should look like. And remove the BaseActor component. It is included in the Player_Character.