Hi,
I am trying to make use of the MVC Pattern in Unity. I am a programming beginner.
Traps and moving Platforms use the same code so i created a base for them. I divide the code into “Data”-class and “Method”-class.
Both objects move to Point A, then to Point B, back to Point A and so on…
Point A and Point B got a trigger, to change the Movementdirection of the Platform/Trap.
The base class holds the data. The subclass gets the data and fills the base data. In the base class i have the object:
public virtual GameObject MovingObject { get { return null; } }
The subclass overrides the property returning null to make it return the right object. I try it this way:
[SerializeField]
private GameObject movingObject;
public override GameObject MovingObject { get { return movingObject; } }
The private variable is set in the Editor and sets the value to the property. This property gives the information to the base class. The problem is that i get null references and I do not know how to fix that. The base class does not return an object. The information get lost on their way to the base…
Is my logic wrong?
If you need to see the whole structure of these six classes you can look it up on
Where exactly does the error get thrown? Because the current snippets are not the source of the error. So please post the complete error, and the complete script the error gets thrown in.
So when i fill the data in the subclasses with the right objects, the base class “MovingObjectsData” say, the EndObject is null. But the subclasses got this object correct. A NullreferenceException appears for the Trap and for the Platform 1 time.