I have one main class called GeneralGameStats
using System;
[Serializable]
public class GeneralGameStats : DataToSave
{
public int hitsTaken;
public float mineralsGathered;
public float timePlayed;
public int tricksUsed;
public int deaths;
public int glideTime;
public virtual void Reset() { hitsTaken = 0; mineralsGathered = 0; timePlayed = 0; tricksUsed = 0; deaths = 0; glideTime = 0; }
}
Then 3 classes will be extending this class
public class LifetimeStats : GeneralGameStats
{
}
public class GameSessionStats : GeneralGameStats
{
}
public class DailyStats : GeneralGameStats
{
public int gamesPlayed;
public override void Reset()
{
base.Reset();
gamesPlayed = 0;
}
}
I then add all these classes on a Scriptable Object called PlayerCharacteristics
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "PlayerStatistics", menuName = "Player Statistics", order = 1)]
public class PlayerStatistics : ScriptableObject
{
[SerializeField]
private DailyStats DailyStats;
[SerializeField]
private LifetimeStats LifetimeStats;
[SerializeField]
private GameSessionStats LastGameSessionStats;
All Classes have the SerializeField Header and GeneralGameStats has the Serializable Header
When the Scriptable Object is created in Unity, only LastGameSessionStats field is serialized.
Am I missing something here? Shouldn’t all fields be serialized with no issue?
