#Ability Instantiation Bug: Returning Null

1 messages · Page 1 of 1 (latest)

drowsy estuary
#

https://codeshare.io/deYZdZ

Hey I think I am running into an instantiation issue, I currently have a set of abilities that from within a list that can be interchagably swapped out on the fly. but none of the abilities can even instantiate or are returning null. Is this because of a parenting issue? Currently the script will is sitting on the parent of the child it's instantiating. I don't really know if this is a beginner or higher question

#

The Prefabs are properly attached, but never instantiate, did I mess up my code? I don't believe this is an inspector issue.

sour reef
#

Where in code exactly do you get the null?

drowsy estuary
#
    private void UseAbility(int slotIndex)
    {
        Debug.Log($"Attempting to use Ability {slotIndex + 1}");

        IAbility ability = abilityManager.GetEquippedAbility(slotIndex);
        if (ability != null && ability.CanUse)
        {
            Debug.Log($"Activating {ability.AbilityName}");
            ability.Activate(firePoint, ability.AbilityPrefab, ability.AbilityForce);
            StartCoroutine(ability.CooldownRoutine());
        }
        else
        {
            Debug.Log($"Ability {slotIndex + 1} is either null or cannot be used.");
        }
    }```
sour reef
#

Is it actually null or CanUse is false? You should debug this kind of conditions thoroughly.

drowsy estuary
#

Good point, I'll fix it and report back

#

Good catch

#

Thank you

#
    private void UseAbility(int slotIndex)
    {
        Debug.Log($"Attempting to use Ability {slotIndex + 1}");

        IAbility ability = abilityManager.GetEquippedAbility(slotIndex);
        if (ability != null)
        {
            if (ability.CanUse)
            {
                Debug.Log($"Activating {ability.AbilityName}");
                ability.Activate(firePoint, ability.AbilityPrefab, ability.AbilityForce);
                StartCoroutine(ability.CooldownRoutine());
            }
            else
            {
                Debug.Log($"Ability {slotIndex + 1} ({ability.AbilityName}) cannot be used (CanUse is false).");
            }
        }
        else
        {
            Debug.Log($"Ability {slotIndex + 1} is null.");
        }
    }```