Errors with a binary formatted save file that works between 4 scripts.

I’m working on a save system for my game. When I needed to pull the variables from one script, it works; but when I tried to do it with the second one as well, the following errors appeared. Does anyone know how to fix them?

Errors:
Assets\Scripts\Player system\PlayerDamage.cs(73,20): error CS7036: There is no argument given that corresponds to the required formal parameter ‘gunMngr’ of ‘SaveSystem.SavePlayer(PlayerDamage, GunManager)’
Assets\Scripts\Weapon system\GunManager.cs(82,20): error CS7036: There is no argument given that corresponds to the required formal parameter ‘gunMngr’ of ‘SaveSystem.SavePlayer(PlayerDamage, GunManager)’

using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;

public static class SaveSystem
{
    public static void SavePlayer (PlayerDamage plyrDmg , GunManager gunMngr) {
        BinaryFormatter formatter = new BinaryFormatter();
        string path = Application.persistentDataPath + "/UPSG.save";
        FileStream stream = new FileStream(path , FileMode.Create);

        PlayerData data = new PlayerData(plyrDmg , gunMngr);

        formatter.Serialize(stream , data);
        stream.Close();
    }

    public static PlayerData LoadPlayer () {
        string path = Application.persistentDataPath + "/UPSG.save";

        if (File.Exists(path)) {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream stream = new FileStream(path , FileMode.Open);

            PlayerData data = formatter.Deserialize(stream) as PlayerData;
            stream.Close();

            return data;
        } else {
            Debug.LogError("Save file missing or corrupted at " + path);
            return null;
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class PlayerData
{
    // Data variables
    public float money;
    public bool boughtAK47;
    public bool boughtM4carbine;
    public bool boughtShotgun870;
    public bool boughtSniperL96;
    public bool boughtExtraHealth;
    public bool boughtExtraHealth2;

    // Initialize player data variables
    public PlayerData (PlayerDamage plyrDmg , GunManager gunMngr) {
        // Player damage script variables
        money = plyrDmg.money;
        boughtExtraHealth = plyrDmg.boughtExtraHealth;
        boughtExtraHealth2 = plyrDmg.boughtExtraHealth2;

        // Gun manager Script
        boughtAK47 = gunMngr.boughtAK47;
        boughtM4carbine = gunMngr.boughtM4carbine;
        boughtShotgun870 = gunMngr.boughtShotgun870;
        boughtSniperL96 = gunMngr.boughtSniperL96;
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class PlayerDamage : MonoBehaviour
{
    public float health = 100f;
    public Text healthText;
    public float damage = 10f;
    public float regenarationSpeed = 2f;
    public float time = 0f;
    public bool boughtExtraHealth;
    public bool boughtExtraHealth2;

    // Physics
    public Rigidbody playerPhysics;
    public float Jump = 10000f;
   
    // Money
    public float money = 1000f;
    public Text moneyText;

    // Health system
    void FixedUpdate(){
        healthText.text = health.ToString("0");
        moneyText.text = money.ToString("0");
        time = time + Time.deltaTime;

        if (time >= regenarationSpeed) {
            time = 0f;
            if (health < 100) {
                health++;
            }
        }
    }

    // Collision triggers
    public void OnCollisionEnter(Collision Collision) {
        if (Collision.collider.tag == "Enemy") {
            TakeDamage();
        } else if (Collision.collider.tag == "Lava") {
            Die();
        } else if (Collision.collider.tag == "Jump") {
            playerPhysics.AddForce(0, Jump, 0);
        } else if (Collision.collider.tag == "Money100") {
            money += 100;
        } else if (Collision.collider.tag == "Money200") {
            money += 200;
        } else if (Collision.collider.tag == "Money500") {
            money += 500;
        } else if (Collision.collider.tag == "Money1000") {
            money += 1000;
        } else if (Collision.collider.tag == "Money10000") {
            money += 10000;
        }
    }

    // Damage
    void TakeDamage() {
        health -= damage;
        if (health <= 0) {
            Die();
        }
    }

    public void Die(){
        SceneManager.LoadScene("MainMenu");
    }

    public void Save () {
        SaveSystem.SavePlayer(this);
    }
    public void Load () {
        PlayerData data = SaveSystem.LoadPlayer();
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GunManager : MonoBehaviour
{
    public GameObject W1;
    public GameObject W2;
    public GameObject W3;
    public GameObject W4;
    public GameObject W5;
    public bool boughtAK47;
    public bool boughtM4carbine;
    public bool boughtShotgun870;
    public bool boughtSniperL96;

    void Start()
    {
        W1.SetActive(true);
        W2.SetActive(false);
        W3.SetActive(false);
        W4.SetActive(false);
        W5.SetActive(false);
    }

    void FixedUpdate()
    {
        if (Input.GetKeyDown("1")) {
            UW1();
        }
        if (boughtAK47 == true && Input.GetKeyDown("2")) {
            UW2();
        }
        if (boughtM4carbine == true && Input.GetKeyDown("3")) {
            UW3();
        }
        if (boughtShotgun870 == true && Input.GetKeyDown("4")) {
            UW4();
        }
        if (boughtSniperL96 == true && Input.GetKeyDown("5")) {
            UW5();
        }
    }

    public void UW1() {
        W1.SetActive(true);
        W2.SetActive(false);
        W3.SetActive(false);
        W4.SetActive(false);
        W5.SetActive(false);
    }
    public void UW2() {
        W1.SetActive(false);
        W2.SetActive(true);
        W3.SetActive(false);
        W4.SetActive(false);
        W5.SetActive(false);
    }
    public void UW3() {
        W1.SetActive(false);
        W2.SetActive(false);
        W3.SetActive(true);
        W4.SetActive(false);
        W5.SetActive(false);
    }
    public void UW4() {
        W1.SetActive(false);
        W2.SetActive(false);
        W3.SetActive(false);
        W4.SetActive(true);
        W5.SetActive(false);
    }
    public void UW5() {
        W1.SetActive(false);
        W2.SetActive(false);
        W3.SetActive(false);
        W4.SetActive(false);
        W5.SetActive(true);
    }

    public void Save () {
        SaveSystem.SavePlayer(this);
    }
    public void Load () {
        PlayerData data = SaveSystem.LoadPlayer();
    }
}

It looks like you changed SavePlayer to take two arguments, but are still just giving it one.

1 Like