0

I am having some trouble with inheritance in Unity. I have two classes, one called Angry and one called Emotion, where Angry inherits Emotion.

Emotion looks like this:

public abstract class Emotion : MonoBehaviour {

    public abstract void initialize(float _strength, float _flux, UMAExpressionPlayer umaExpression);
    public abstract void emote();

    public void initialize(float _strength, float _flux, float _duration, UMAExpressionPlayer _umaExpression){
        initialize(_strength, _flux, _umaExpression);
    }

    void Update()
    {

    }
}

And Angry looks like this:

public class Angry : Emotion {

    public override void initialize(float _emotion_strength, float _flux, UMAExpressionPlayer _umaExpression) {

    }

    public override void emote()
    {

    }
}

Now to the problem. Instantiating Angry always returns null. I.e. (new Angry() == null) always returns true. But if i remove the inheritance from MonoBehaviour, i.e. remove ": MonoBehaviour" from Emotion, this stops being the case and I get an instance of Angry. Why is this? What am I missing here?

Grisungen
  • 333
  • 2
  • 7

1 Answers1

0

Turns out it is because I'm using "new()". I must use AddComponent when MonoBehaviour is inherited.

Grisungen
  • 333
  • 2
  • 7