My projectiles are sometimes getting stuck to my "shield" - weird exceptions in AnimatorAudioState

AKB

Member
Unity: 2021.2.0f
UCC: 2.4.2

Hi there. I am noticing that some of my Projectile GameObjects would stick to my shield when they hit. I have a bit of a custom setup in that I have created some meteors that have Projectile components but these are not fired from the normal ShootableWeapon (info below) etc. When some projectiles impact and I have "apply Impact" on my shield I get an exception firing.

NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Items.AnimatorAudioStates.Sequence.NextState () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/AnimatorAudioStates/Sequence.cs:55)
Opsive.UltimateCharacterController.Items.AnimatorAudioStates.AnimatorAudioStateSet.NextState () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/AnimatorAudioStates/AnimatorAudioStateSet.cs:217)
Opsive.UltimateCharacterController.Items.Actions.Shield.Damage (System.Object source, System.Single amount) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Shield.cs:127)
Opsive.UltimateCharacterController.Objects.Destructible.OnCollision (System.Nullable`1[T] hit) (at Assets/Opsive/UltimateCharacterController/Scripts/Objects/Destructible.cs:226)
Opsive.UltimateCharacterController.Objects.Projectile.OnCollision (System.Nullable`1[T] hit) (at Assets/Opsive/UltimateCharacterController/Scripts/Objects/Projectile.cs:66)
Opsive.UltimateCharacterController.Objects.TrajectoryObject.Move (UnityEngine.Vector3& position, UnityEngine.Quaternion rotation) (at Assets/Opsive/UltimateCharacterController/Scripts/Objects/TrajectoryObject.cs:588)
Opsive.UltimateCharacterController.Objects.TrajectoryObject.FixedUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Objects/TrajectoryObject.cs:512)


Turning off ApplyImpact makes these go away for the most part, but during initialisation there is still one left along a different code path.
NullReferenceException: Object reference not set to an instance of an object

Opsive.UltimateCharacterController.Items.AnimatorAudioStates.AnimatorAudioStateSet.DeserializeAnimatorAudioStateSelector (Opsive.UltimateCharacterController.Items.Item item, Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion characterLocomotion) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/AnimatorAudioStates/AnimatorAudioStateSet.cs:129)
Opsive.UltimateCharacterController.Items.Actions.Shield.Awake () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Shield.cs:89)
UnityEngine.GameObject:SetActive(GameObject, Boolean)
Flightless.UCC.Abilities.UseShield:AbilityStarted() (at Assets/_DArk/Scripts/abilities/UseShield.cs:36)
Opsive.UltimateCharacterController.Character.Abilities.Ability:StartAbility(Int32) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Ability.cs:476)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:TryStartAbility(Ability, Boolean, Boolean) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1198)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:TryStartAbility(Ability, Boolean) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1065)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:TryStartAbility(Ability) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1054)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotionHandler:TryStartAbility(Ability) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:235)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotionHandler:UpdateAbilityInput(Ability[]) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:131)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotionHandler:UpdateAbilityInput() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:98)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotionHandler:Update() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotionHandler.cs:73)


The Projectile behaviour looks like this

1636393337742.png
And my "shield" is as follows.

1636393405542.png


My setup is as follows. When the shield is pulled out with a custom action, I just enable a GO. This GO has the Shield script on it. When my projectiles (meteors with the Projectile component) are instantiated I call Initialize on them and then let everything goes. For the most part when they hit the ground they explode nicely etc but if they hit my shield, they can stick there.

Any ideas? I can turn off ApplyImpact if I need to but the initialisation is still a bit of a problem and I'd like to know what I'm doing wrong.
 

Attachments

  • 1636393506356.png
    1636393506356.png
    10.8 KB · Views: 0
Can you update to the latest version and then post what line number is causing the problem? Line 55 within Sequence.cs is an int assignment so it'll never throw that exception.
 
OK I have updated and the errors are in the same place. I managed to get some time to do some debugging and the exceptions were happening because m_Item of the shield was null. I had not put an Item component on my shield. I hadn't done this because I didn't want my Item to actually be an item - it's not equipped per se and unequipped and I didn't want to do that so I had to switch it out.

I am using categories to handle some of my items and keep them equipped independently, but I was wondering if it's possible to have bunches of items, that aren't really "equipped" as far as the UCC system goes, but I can use with item actions, say instanced of "Use" or somesuch? E.G I might have a scanner, a shield, some other things that I don't need to switch to but I just want to use, without them having to be equipped. At the moment I have a scanner type item which is working but it's the only one in that category/item set so it's all ok. If I added more items to the item set, do I have to switch to them first or can I just USE them? Basically I'm still trying to find out the best way to handle lots of "insta shot" items and aren't really equipped.
 
Yeah unfortunately that's the way item actions are designed. For items that are always "equipped" independently of one another, the solution is to use additional item slots. You can have any number of item slots, so you can easily have a separate item slot for each item.
 
Thanks. I Initially tried, saw that the Use ability could only listen to 3 slots max (debug log) and moved on but looking at it again it might still be able to track the generic event if I need it.

Does the Ultimate Inventory System integrated with UCC solve any of these problems? That is, can I setup actions directly on to inventory items so have a bunch of ones with their own activation buttons and they can just Use immediately without equipping (Or be equipped automatically?)
 
Last edited:
All items need to be equipped. You can add any number of EquipUnequip abilities and any number of slots but all items need to be equipped in order to be used. This is independent of the inventory system.
 
Top