# Unexpected ScriptableObject Behaviour

I am currently working on a game which should be your basic RPG style and in this game I am using an Ability system based on ScriptableObjects. Each Ability has its own ParticleSystem (prefab) and AudioSource.

Basically all Ability.asset files are added to a list of Abilities. Using PageUp/Down buttons the player equips the next/previous Ability of the List.

When "Fire1" is pressed the ability is then cast which works just fine before equipping the next Ability. Then, no matter how many times I press "Fire1" no Ability is cast unless I click out of game-view and inside of it again. However in the Inspector everything seems OK.

Here's my code:

void Update ()
{
abilityCount = AbilitySystem.Instance.allAbilities.Count - 1;
abilityCooldown -= Time.deltaTime;
if(Input.GetButtonDown("Fire1") && abilityCooldown <= 0f)
{
Shoot();
abilityCooldown = 1f / castingSpeed;
}

if (Input.GetKeyDown(KeyCode.PageDown))
{
abilityIndex--;
if (abilityIndex < 0)
{
abilityIndex = abilityCount;
}
currentAbility = AbilitySystem.Instance.allAbilities[abilityIndex];
UpdateAbilityStats();
}

if (Input.GetKeyDown(KeyCode.PageUp))
{
abilityIndex++;
if (abilityIndex > abilityCount)
{
abilityIndex = 0;
}
currentAbility = AbilitySystem.Instance.allAbilities[abilityIndex];
UpdateAbilityStats();
}

}

void UpdateAbilityStats()
{
abilityDamage = currentAbility.abilityDamage;
abilityRange = currentAbility.abilityRange;
abilityCooldown = currentAbility.abilityCooldown;
particles = currentAbility.Particles;
particlesOnTarget = currentAbility.onTargetParticles;
}

• My guess is castingSpeed becomes 0f and you get float.PositiveInfinity on abilityCooldown, then no matter what you subtract to that, it should never change. Oct 16, 2017 at 16:19
• @Alakanu how can I be so stupid, man you were absolutely right. Thanks. Oct 16, 2017 at 16:50
• @Alakanu that sounds like it's worth posting as an answer so it can be marked Accepted. Oct 16, 2017 at 17:38
• cheers, glad to help out Oct 17, 2017 at 10:09