Cannot play disabled audio source(only affects player?)

I’m toward the end of the Combat course in the RPG bundle, in the final polish section where I’ve overhauled my models. Something’s gone wrong on my player prefab, though, because now when I play the game and attack someone, it says:

Can not play a disabled audio source
UnityEngine.Events.UnityEvent:Invoke ()
RPG.Combat.Weapon:OnHit () (at Assets/Scripts/Combat/Weapon.cs:13)
RPG.Combat.Fighter:Hit () (at Assets/Scripts/Combat/Fighter.cs:86)


Here is a screenshot of my Equipped Unarmed prefab, although this is happening no matter which weapon I equip.

The weird thing is, this is only affecting my player. The Archer prefab and a wolf prefab all make their attack and damage/die sounds properly. They all derive from the same character prefab. I even tried deleting my Player prefab and recreating it as a fresh variant of the Character prefab, but the same thing occurs.

Here’s a look at my Player prefab:

Update: I fixed the weapon hit sound, turns out the slot I’d put for Right Hand/Left Hand transform was disabled, so enabling that fixed it.

Now I’m not getting any errors, but the Archer is still grunting and such when he dies whereas the Player is not. Not sure what’s causing that.

The sound that originates from the Fighter when you hit should be from the attached weapon. For example, if you have a sword, all of the sword sounds should originate from an AudioSource on the sword itself. (Same with the bow, or the unarmed). This should respond to when Fighter calls the Weapon’s OnHit() method, which invokes the Weapon’s OnHit UnityEvent.

The sound that the character makes when they are hit should be on the DamageSFX. You’ll link that sound up with the Character’s Health.TakeDamage Unity Event.

The sound that the character makes when they die should be on the DieFX, which will be linked up to the character’s Health.OnDeath UnityEvent.

image

Yes, I’m aware. It was working perfectly yesterday. Further, it is still working on the enemies, so the code likely isn’t the culprit. Here’s a shot of my TakeDamage code, my Health script in the Inspector, and shots of my DamageSFX game objects.

It’s also not having a problem updating and displaying my damage text over the player’s head.

Die sound:

Damage sound:

@Brian_Trotter

UPDATE: I’ve narrowed the problem down! It is only projectiles that are failing to trigger the Take Damage SFX. If the player uses a Bow or Fireball, the enemy does not grunt when hit(but does cry when killed). If the player is attacked by a Bow, she has the exact same behavior. But if the attack is Unarmed or Sword, the hit grunt SFX plays accurately!

Do you have any idea what could be causing that?

The grunt should be being called by the UnityEvent TakeDamage, which is called within the target’s Health.TakeDamage method.

What I can’t think of is a reason why that TakeDamage event would not sound when the damage source is a projectile.

Paste in your Health.TakeDamage method and we’ll take a look.

        public void TakeDamage(GameObject instigator, float damage)
        {
            healthPoints.value = Mathf.Max((healthPoints.value - Mathf.Abs(damage)), 0);
            if(healthPoints.value == 0)
            {
                onDie.Invoke();
                Die();
                AwardExperience(instigator);
            }
            else
            {
                takeDamage.Invoke(damage);
            }
        }

So this looks correct. The character should be generating the grunt sound effect when he or she or it gets hit, regardless of the damage source unless the character is killed outright, in which case they should only be gasping in death…

It occurs to me, you may not be hearing the gasp because the sound is being attentuated (3d sound means the further from the source of the sound you are, the quieter (or even so quiet you can’t hear it), the sound will be.

So, you pointed me in the right direction. It wasn’t that the sound was too far away(like I said, I could hear it fine when the weapon I was being attacked with was a sword, so the player was the exact same distance from the boom mic as when being attacked with a bow). But actually, the hit sound of the arrow and the fireball were both so loud that I couldn’t hear the grunt. I turned their volume down to half and I was able to hear the grunts!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms