Re: Migrating Level Manager to Dialogue System
Posted: Sat Oct 03, 2020 9:50 am
Hi Tony,
Apologies for getting back to you so late. I gave the manual another read and I understand what it does now. To extend the saving functionality to capture my player data, I wrote another custom saver to . I am just running into a bit of difficulty in getting the reference of scriptable objects I use for my player inventory to apply properly even though it seems to be deserializing correctly. My code is as follows:
The player save data class is a serializable class like the loot chest data we walked through earlier.
I can see the inventories getting printed when ApplyData is being called but I am not sure why they are not copying over when this approach works for the LootChest controller. What's weirder is that the gun inventory and storage seem to be copying over fine.
I'm sure this is not a Dialogue System error but figured I'd just post it here while i figure out what is going on. If you think you know what is going on please feel free to let me know.
Apologies for getting back to you so late. I gave the manual another read and I understand what it does now. To extend the saving functionality to capture my player data, I wrote another custom saver to . I am just running into a bit of difficulty in getting the reference of scriptable objects I use for my player inventory to apply properly even though it seems to be deserializing correctly. My code is as follows:
Code: Select all
public override void Start()
{
inventory = GetComponent<PlayerInventory>();
gunInventory = GetComponentInChildren<GunController>();
playerStatus = GetComponent<PlayerStatus>();
playerHealth = GetComponent<PlayerHealthController>();
saveData = new PlayerSaveData();
saveData.inventory = new InventoryObjectTemplate[inventory.inventoryList.Length];
saveData.storyInventory = new InventoryObjectTemplate[storyInventory.itemList.Length];
}
public override void ApplyData(string data)
{
if (string.IsNullOrEmpty(data))
{
//Debug.Log("no save detected, implementing original data");
}
else
{
print("applying player data");
PlayerSaveData saveData= SaveSystem.Deserialize<PlayerSaveData>(data);
print(data);
inventory.inventoryList = saveData.inventory;
storyInventory.itemList = saveData.storyInventory;
gunInventory.guns = saveData.gunsInventory;
gunStorage.storedGuns = saveData.gunStorage;
playerHealth.health = saveData.health;
playerHealth.defaultMaxHealth = saveData.maxHealth;
playerStatus.hunger = saveData.hunger;
playerStatus.hPText.text = saveData.health.ToString();
playerStatus.hungerText.text = saveData.hunger.ToString();
}
}
public override string RecordData()
{
if (SaveSystem.instance != null)
{
saveData.inventory = inventory.inventoryList;
saveData.storyInventory = storyInventory.itemList;
saveData.gunsInventory = gunInventory.guns;
saveData.gunStorage = gunStorage.storedGuns;
saveData.health = playerHealth.health;
saveData.maxHealth = playerHealth.defaultMaxHealth;
saveData.hunger = playerStatus.hunger;
}
return SaveSystem.Serialize(saveData);
}
Code: Select all
[System.Serializable]
public class PlayerSaveData
{
public InventoryObjectTemplate[] inventory;
public InventoryObjectTemplate[] storyInventory;
public GunTemplate[] gunsInventory;
public GunTemplate[] gunStorage;
public int hunger;
public int health;
public int maxHealth;
}
I'm sure this is not a Dialogue System error but figured I'd just post it here while i figure out what is going on. If you think you know what is going on please feel free to let me know.