Values passed into function becoming 0?

Hey first time posting so apologize for mistakes.

I have a function that loops through targeted enemies and they take damage if they are in attack range. The problem is that when I passes a variable into the function, it becomes 0 no matter what I initialize the value to. I’ve made sure to initialize it in both the start function as well as the inspector, but it keeps zeroing out. When I pass a number instead of a variable, it works.

Here is my attack function:

private void LightAttack(InputAction.CallbackContext context)
    {
        try{
            GameObject.FindGameObjectWithTag("AttackPoint").GetComponent<Animator>().SetTrigger("KnightAttack1");
            foreach(GameObject enemy in enemyTargets)
            {
                enemy.GetComponent<Enemy>().Damage(lightAttackDamage); 
            }
            //Debug.Log("Light Attack");
        }
        catch
        {
            Debug.Log("Something went wrong");
        }
    }

And here is my damage function:

   public void Damage(int damage)
        {
            StartCoroutine("FlashRed");
            
            Debug.Log(gameObject.name + " health: " + health);
            health -= damage;
    
            if(health <= 0)
            {
                Destroy(gameObject);
            }
            
            Debug.Log(gameObject.name + " took " + damage + " damage.");
      
        }

I’ve tried changing the variable type as well but to no avail. Any help would be appreciated.

Well, it’s not clear where and how you call your LightAttack method. However I suspect you may be calling it on a prefab instead of the instance in the scene. This can easily happen when you linked up the methods in the inspector as delegates / UnityEvents and you actually linked the prefab.

Try adding this line to the very beginning of your LightAttack method:

Debug.Log("LightAttack: lightAttackDamage = "+lightAttackDamage, gameObject);

The important part is the second argument to the Log method. It’s a context object and we simply pass our own gameobject. When you pass a context object to Log, Unity will remember that object and when you click on the log message in the console, Unity will highlight that object. This makes it very easy to identify which object is actually used.