'Unity abstract inheritance issues

I've been trying to work with inheritance but in quite new to this in c# so I'd like a little help.

The base class is:

public abstract class Possessable : Monobehaviour
{
    public bool isPossessed = false;
    private InputDataSO _inputData;

    public void Possess(InputDataSO data)
    {
        this.isPossessed = true;
        this._inputData = data;
    }

    public void Depossess()
    {
         this.isPossessed = false;
    }
}

There are a few classes which extend the base class.

However the main useage is in the Player manager class. PlayerManager.UsePossessable() is called, however the bool isPossessed doesn't change, and the inputData dependency isn't injected as expected. What am I doing wrong?

public class PlayerManager : Monobehaviour
{
    public Possessable currentPossessable;
    public InputDataSO inputData;

    public void UsePossessable(Possessable item)
    {
        currentPossessable.Depossess();
        currentPossessable = item;
        currentPossessable.Possess(inputData);
    }
}

Edit: I'm on mobile so this is REALLY hard. currentPossessable and other variables in PlayerManager are initialised properly and this has been checked. This just shows the minimum code to reproduce the issue.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source