Properly serialized class is loaded as null
Posted: Mon Mar 13, 2023 5:54 pm
We have an interface (IRelic) implemented by an abstract class (ARelic) itself implemented by lots of classes.
The goal is to save all relics into a List. Here is the list of classes :
Here is one Relic example:
When I save this relic with it works fine (I actually don't specify the ARelic generics type, because the relics are all contained into a List<ARelic>), it's properly saved to the save file :
But when I load it with it returns null.
I have noticed that if I add a public int field to the BloodVialRelic, it's properly loaded. Any relic that has no public fields does return null when loaded, while any relic with public supported field types by ES3 return the proper value.
What's up with that ? I don't need fields in all of them, and I don't see why loading a class that has no public fields would output null.
The goal is to save all relics into a List. Here is the list of classes :
Code: Select all
public interface IRelic
{
public string Name { get; }
public string Description { get; }
public RelicRarity Rarity { get; }
public Character Character => Character.Any;
}
Code: Select all
[Serializable]
public abstract class ARelic : IRelic
{
public abstract string Name { get; }
public abstract string Description { get; }
public abstract RelicRarity Rarity { get; }
}
Code: Select all
public class BloodVialRelic : IRelic, IEventHandler<OnPlayerTurnStartedEvent>
{
public string Name => "Blood Vial";
public string Description => "Heal 5 HP at the start of combat.";
public RelicRarity Rarity => RelicRarity.Common;
private readonly GlobalEventBusMono eventBus;
public BloodVialRelic()
{
// some code
}
public void Handle(OnPlayerTurnStartedEvent evt)
{
// some code
}
}
Code: Select all
ES3.Save<ARelic>("Relic", bloodVialRelic)
Code: Select all
"__type" : "ClubSandwich.Relics.BloodVialRelic,ClubSandwich.Relics"
Code: Select all
ES3.Load<ARelic>("Relic", bloodVialRelic)
I have noticed that if I add a public int field to the BloodVialRelic, it's properly loaded. Any relic that has no public fields does return null when loaded, while any relic with public supported field types by ES3 return the proper value.
What's up with that ? I don't need fields in all of them, and I don't see why loading a class that has no public fields would output null.