Sword object being "shared" between characters

DavidC

Active member
2020.3.7f1
UCC 2.3.2
UIS 1.1.7
UMA, Digger Pro, A*

On "Necromancer" (NPC), place the sword into Equipment Slots.
Start playmode.
As the player, walk over the sword pickup & bow pickup
Equip Sword & Equip Bow.
Sword Object throws error.
If you switch from "sword" to "bow" it'll enable/disable rendering of the sword in the necromancer's hands.


Error: Unable to find the base object for item OpSword. Ensure the item specifies a base object under the First Person Perspective Item component.
UnityEngine.Debug:LogError (object)
Opsive.UltimateCharacterController.FirstPersonController.Character.FirstPersonObjects:CheckActiveBaseObjects () (at Assets/Opsive/UltimateCharacterController/Scripts/FirstPersonController/Character/FirstPersonObjects.cs:357)
Opsive.UltimateCharacterController.FirstPersonController.Character.FirstPersonObjects:StartEquip (Opsive.UltimateCharacterController.Items.Item,int) (at Assets/Opsive/UltimateCharacterController/Scripts/FirstPersonController/Character/FirstPersonObjects.cs:328)
Opsive.UltimateCharacterController.FirstPersonController.Items.FirstPersonPerspectiveItem:StartEquip (bool) (at Assets/Opsive/UltimateCharacterController/Scripts/FirstPersonController/Items/FirstPersonPerspectiveItem.cs:852)
Opsive.UltimateCharacterController.Items.Item:StartEquip (bool) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Item.cs:455)
Opsive.UltimateCharacterController.Character.Abilities.Items.EquipUnequip:ItemEquip (int,bool) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/EquipUnequip.cs:1000)
Opsive.UltimateCharacterController.Character.Abilities.Items.EquipUnequip:Update () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/EquipUnequip.cs:665)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:UpdateAbilities (Opsive.UltimateCharacterController.Character.Abilities.Ability[]) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:794)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:UpdateUltimateLocomotion () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:725)
Opsive.UltimateCharacterController.Character.CharacterLocomotion:Move (single,single,single) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:477)
Opsive.UltimateCharacterController.Game.KinematicObjectManager/KinematicCharacter:Move (bool) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/KinematicObjectManager.cs:237)
Opsive.UltimateCharacterController.Game.KinematicObjectManager:FixedUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/KinematicObjectManager.cs:880)
 
Last edited:
Thank you for sending your project,

The first issue I see is that you have two errors with the Necromancer NPC.
It complains that you have Item Sets that do not have an Equip Item Action for the Item Set Category.

So I added those item abilities and made sure to have one for each Item Set Category:
1621955832635.png

As for the error you mentioned above, the issue is that your first person perspective item component can't find the First Person Base object.
I'm not sure why but your prefab component Object field was set to First Person OpSword and First Person Base Object ID was set to -1. That's not how you setup first person perspective items.
Remove the First Person Object and Item Slot Components that are on the "First Person OpSword" gameobject.
The set the Object field to none and the "First Person Base Object ID" to 0, which is what you use for your First Person Arms under your character (it moves under the camera at runtime)
1621957521987.png
1621956958974.png

Doing that caused some issues on your Necromancer which should not be using first person perspective item but is trying to.
The error went away once I Removed the "First Person Objects" from under the Necromancer.
That being said the NPCs shouldn't be trying to equip items that have a first person perspective if they aren't setup to do so.

So I would suggest having two item prefabs one for you character which would have both first and third person perspectives and another one that is only third person for your NPCs.
On the Inventory Bridge you can set the name of the attribute where your item prefab is set. So you can have a different attribute name for your character item prefabs and your NPC item prefabs.

Of course that's only necessary if you wish for your character to be usable in first person view, otherwise you could use the same prefabs for everything and only use the third person view
 
  1. Added abilities, errors are eliminated
  2. Removed base object and set base object ID to 0 (probably an error on my part in the UCC Item wizard
    1. Tried removing Necromancer First Person Objects, First Person components and first person sword under sword prefab. Still had the same problem where only one sword was rendered (in necromancer's hand), and switching to the bow made it stop being rendered.
    2. (Instead of above) Tried adding an empty transform to Necromancer with the first person base object script to the Necromancer. This removed the error regarding the first person objects. But the single sword problem persisted.
After your did the fixes, did you check to see if both characters had a sword being rendered?

If I click on the reference fields for the sword under the player, it highlight's the corresponding sword objects in the Necromancer's hands.
 
Last edited:
Well that was a hard one to debug.

1622020019256.png
The issue is that you've used an attribute binding to bind the OpSword to the Prefab. The issue here is that when your item spawns the OpSword becomes the instance and the attribute binds to it. Therefore the itemDefinition is now using the instance of the item instead of the original prefab. So when the second sword is spawned it uses the instance in the necromancer which messes up everything.

Remove the that binding and that should solve your issue.

To clarify, binding should be used 90% of the time on the Item Attributes. Only use bindings to Item Definition and Category attributes when you are using the binding as read-only. There is no built-in way to prevent you from modifying a item definition or category attribute at runtime when it is bound to a value.

Here you can see both your character and npc with a sword.
1622020112728.png
 
Top