Shield Attribute in the Character Health of the AI agent gives an error if set to None

FadelMS

Member
As the title says, if the Shield Attribute is set to None (Default), it generates the following error:
ArgumentNullException: Value cannot be null.
Parameter name: key
System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (TKey key) (at <695d1cc93cca45069c528c15c9fdd749>:0)
.
.
.
But if it is set to Health, the error goes away. Is there a way to remove the Shield Attribute altogether from the Health if it is not needed?
 
Here is the full error:

ArgumentNullException: Value cannot be null.
Parameter name: key
System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (TKey key) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].TryGetValue (TKey key, TValue& value) (at <695d1cc93cca45069c528c15c9fdd749>:0)
Opsive.Shared.Events.EventHandler.GetActionList (System.Object obj, System.String eventName) (at <27da9e1afec54f2fb2a11d46a234f9df>:0)
Opsive.Shared.Events.EventHandler.ExecuteEvent[T1] (System.Object obj, System.String eventName, T1 arg1) (at <27da9e1afec54f2fb2a11d46a234f9df>:0)
Opsive.UltimateCharacterController.Traits.Attribute.set_Value (System.Single value) (at Assets/Opsive/UltimateCharacterController/Scripts/Traits/AttributeManager.cs:56)
Opsive.UltimateCharacterController.Traits.Health.OnDamage (System.Single amount, UnityEngine.Vector3 position, UnityEngine.Vector3 direction, System.Single forceMagnitude, System.Int32 frames, System.Single radius, UnityEngine.GameObject attacker, System.Object attackerObject, UnityEngine.Collider hitCollider) (at Assets/Opsive/UltimateCharacterController/Scripts/Traits/Health.cs:347)
Opsive.UltimateCharacterController.Traits.CharacterHealth.OnDamage (System.Single amount, UnityEngine.Vector3 position, UnityEngine.Vector3 direction, System.Single forceMagnitude, System.Int32 frames, System.Single radius, UnityEngine.GameObject attacker, System.Object attackerObject, UnityEngine.Collider hitCollider) (at Assets/Opsive/UltimateCharacterController/Scripts/Traits/CharacterHealth.cs:87)
Opsive.UltimateCharacterController.Traits.Health.Damage (System.Single amount, UnityEngine.Vector3 position, UnityEngine.Vector3 direction, System.Single forceMagnitude, System.Int32 frames, System.Single radius, UnityEngine.GameObject attacker, System.Object attackerObject, UnityEngine.Collider hitCollider) (at Assets/Opsive/UltimateCharacterController/Scripts/Traits/Health.cs:274)
Opsive.UltimateCharacterController.Items.Actions.MeleeWeapon.HitCollider (Opsive.UltimateCharacterController.Items.Actions.MeleeWeapon+MeleeHitbox hitbox, UnityEngine.RaycastHit raycastHit, UnityEngine.GameObject hitGameObject, UnityEngine.Collider hitCollider, Opsive.UltimateCharacterController.Traits.Health hitHealth) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/MeleeWeapon.cs:803)
Opsive.UltimateCharacterController.Items.Actions.MeleeWeapon.HitCollider (System.Int32 hitboxIndex, UnityEngine.Collider other, Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion hitCharacterLocomotion) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/MeleeWeapon.cs:755)
Opsive.UltimateCharacterController.Items.Actions.MeleeWeapon.UseItemUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/MeleeWeapon.cs:598)
Opsive.UltimateCharacterController.Character.Abilities.Items.Use.LateUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/Use.cs:624)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.LateUpdateActiveAbilities (Opsive.UltimateCharacterController.Character.Abilities.Ability[] abilities, System.Int32& abilityCount) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1042)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.LateUpdateUltimateLocomotion () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1028)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.UpdatePositionAndRotation () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:843)
Opsive.UltimateCharacterController.Character.CharacterLocomotion.UpdatePositionAndRotation (System.Boolean fromAnimatorMove) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:517)
Opsive.UltimateCharacterController.Character.CharacterLocomotion.OnAnimatorMove () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:1453)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.OnAnimatorMove () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1772)
 
Hmm, how can I reproduce that error in the demo scene? The shield attribute on the Nolan character is set to none.
 
The shield of Nolan does not produce any errors. The problem is with the shield of the AI Agent. When I add Shield Attribute to the Attribute Manager and assign it to the Shield value in the Character Health, the error goes away.
The AI Agent is equipped with a melee weapon with category melee blade ( I'm using IntegrationDemoInventoryDatabase) and the Use Ability is activated in coroutine in the following code:
Code:
IEnumerator startAbilty()
    {
        while (enemyHealth.IsAlive())
        {
                enemy_CharacterLocomotion.TryStopAbility(useAbility);
                yield return new WaitForSeconds(5.0f);
                if (useAbility != null && playerHealth.IsAlive())
                {
                    enemy_CharacterLocomotion.TryStartAbility(useAbility);
                    meleeWeapon.UseItemUpdate();
                }
        }
    }
 
Last edited:
The character health component doesn't care if the character is an AI agent or player controlled agent. In the demo scene I tried to reproduce the error by adding the Character Health component with no shield attribute to Agent Nolan but I did not receive the error.
 
I'm just describing the case.
Maybe the line of code "meleeWeapon.UseItemUpdate();" is causing the error! The damage does not take place unless I use this line. Is there another way to update damage?
 
Yes, the Use ability will call the methods required. My guess is that with you manually calling the update method the object hasn't been fully initialized so you are getting the error. You can use a similar setup as the demo scene where Agent Nolan uses the Use ability to swing their sword.
 
I'm using the integration demo where Nolan swings the sword by pressing the left button while I'm using a trigger to start the Use ability and it doesn't work unless I use the code mentioned earlier. I guess "TryStartAbility(useAbility)" should work without using "UseItemUpdate()" but it doesn't. I know I'm missing something in the setup but I couldn't figure it out.
 
You definitely shouldn't ever need to manually call UseItemUpdate. Where exactly are you starting this startAbilty() coroutine? And when you say "the damage does not take place", do you mean the Use ability starts as normal but no damage occurs, or the ability doesn't even start?
 
The startAbilty() coroutine is placed in a trigger attached to the AI agent, and "CharacterLocomotion.TryStartAbility(useAbility)" returns True but the melee weapon does not inflict any damage to the main player (Nolan) unless I use UseItemUpdate. I tried meleeWeapon.UseItem and meleeWeapon.StartItemUse but they don't do anything. I placed meleeWeapon.IsItemInUse in the Update to check its value and it is always False even after using UseItemUpdate.
 
The reason I ask about where your startAbility coroutine gets started is because if it's getting called too often for some reason (e.g. the trigger is called every frame or something) then the TryStopAbility will repeatedly call too. So I'd double check that that's not happening. But it sounds like the Use ability does actually activate in-game (you see the Use animation etc), and it's just that the collision with the character doesn't get detected?
 
Top