What happened to BridgeEquippableProcessing?

Yes it was removed.
The logic is similar, you have 3 steps.

1) Item is in the Inventory
2) Item is in the Equippable ItemCollection (the bridge takes them into account as character items)
3) The item can be actively equipped.


before there was an intermediary step between 2 and 3 where an item could be in an equippable collection but not be soft equipped. That was removed to simplify things.

So now any item within the Equippable ItemCollections is watched by the bridge, and can be actively equipped.

So of the logic from BridgeEquippableProcessing was split between the UCC Inventory and the ItemSetManager classes
 
Hmm okay, I had a use case using the old system where I tried to spawn all possible weapons on the character when the character was spawned, then whenever the player would equip an inventory item it would use that already spawned character item to improve runtime performance.

How would I implement this with the new system? It seems like InitializePreAddedCharacterItems could handle the initialization? So I could just add the weapon prefabs directly to my character prefab and set them as inactive?
 
Yes,
The system now allows both runtime added items and pre-runtime added items.

By default the items are pooled. So even if you add them at runtime, you can add everything at the start of the game, remove everything and than add them back when needed without causing performance issues.
I prefer this way, because it keeps things clean within prefabs and avoid manual mistakes when you forget or mistakenly make changes on prefab overrides
 
When you say add everything at the start of the game, does that mean I can include the item prefabs in the object pool (which would create them without an associated character), or does it mean that I need to create custom code to instantiate and then destroy the items in an Awake or Initialize function?
 
You would need to create custom code to initialize the weapon properly for that character.
Just pre-pooling them directly without going through the character will most likely cause issues (I haven't tried myself though). But even if it does work the Initialize section of the item will still need to be processed later and that does take some processing time which could be hidden during a loading screen if you do it through the character in a custom script during the initialization of your scene/game
 
So just so I understand the custom code approach, if I created a custom item collection and added the item identifiers I wanted to pre-spawn to that collection, then I would just need to:

  1. Call SpawnItemIdentifiersCharacterItem(itemIdentifier, slotID) for each item identifier in the collection. This spawns the character item without adding it to the inventory?
  2. Call RemoveCharacterItem(characterItem, false) to remove the character item but not destroy it?
Am I missing anything else?
 
So I ran into a couple issues. To make it work properly, I had to modify the following:


1. Override DestroyCharacterItem as follows.

C#:
        /// <summary>
        /// Destroy the character item. Pre-Runtime character items can only be destroyed if forced.
        /// </summary>
        /// <param name="characterItem">The character item to destroy.</param>
        /// <param name="forceDestroy">Force destroy even if the character item is a pre-runtime character item.</param>
        /// <returns>Returns true if the character item was destroyed successfully.</returns>
        public override bool DestroyCharacterItem(CharacterItem characterItem, bool forceDestroy = false)
        {
            if (m_CachedCharacterItems.Contains(characterItem))
            {
                // Don't destroy cached character items.
                return true;
            }
          
            return base.DestroyCharacterItem(characterItem, forceDestroy);
        }

2. Override InitializePreAddedCharacterItems as follows:

C#:
        /// <summary>
        /// This function will scan the Items in the ItemPlacement component and initialize all the CharacterItems.
        /// </summary>
        protected override void InitializePreAddedCharacterItems()
        {
            // Do nothing, since we only want to initialize pre-added items when they are picked up.
        }

Both these can be overriden through my inherited class which was totally fine.

3. Change OnCharacterItemSpawned as follows:

C#:
        /// <summary>
        /// When a character item is spawned send events to notify objects outside the inventory.
        /// </summary>
        /// <param name="characterItem">The character Item that was added.</param>
        public virtual void OnCharacterItemSpawned(CharacterItem characterItem)
        {
            if (!m_ValidCharacterItems.Contains(characterItem)) {
                m_ValidCharacterItems.Add(characterItem);
            }
          
            /*
            if (m_AllCharacterItems.Contains(characterItem)) {
                return;
            }
            */

            EventHandler.ExecuteEvent(m_GameObject, "OnInventoryWillAddItem", characterItem);

            // @CustomCode Start: Only add the character item if its not already in all character items.
            if (!m_AllCharacterItems.Contains(characterItem))
            {
                m_AllCharacterItems.Add(characterItem);
                m_CharacterItemsBySlot[characterItem.SlotID].Add(characterItem);
            }
            // @CustomCode End
          
            // Notify those interested that an item has been added.
            EventHandler.ExecuteEvent(m_GameObject, "OnInventoryAddItem", characterItem);
            if (m_OnAddItemEvent != null) {
                m_OnAddItemEvent.Invoke(characterItem);
            }

            // The ItemIdentifier event should also be called in cases where the amount is greater than 0.
            // This allows the ItemIdentifier to be picked up before the item has been added.
            if (GetItemIdentifierAmount(characterItem.ItemIdentifier) > 0) {
                OnItemIdentifierPickedUp(characterItem.ItemIdentifier, characterItem.SlotID, 1, false, false);
            }
        }

I didn't understand why this function originally returns early if all characters items contains the character item already?
 
Last edited:
I didn't understand why this function originally returns early if all characters items contains the character item already?
If the item exists in m_AllCharacterItems, it means that was is aleady spawned on the character.
So it doesn't need to be added again.

There is a difference between adding the item and spawning it. Because you can keep an item that was previously spawned but was removed (amount of 0) without destroying the item, such that it can be cached for the next time you pickup the item.

I hope that makes sense
 
Top