Multiple characters - one inventory

desukarhu

Member
Hi,

How would I go about creating a system and (UI to go along with it) where I have one shared inventory with multiple characters that can equip items from that inventory?

Something like in Divinity Original Sin, where the inventory is on the right and equipment on the left?

xn57gvlp6up11.png
 
Hi desukarhu

In our system an inventory is simply a collection of items. Therefore you could make it seem like they all share the same inventory but actually all your characters have their own small inventory (with the equipped items) and then you have the "player" inventory which you share between your characters.

To design this you'll have two choices.

1)Have a single big inventory with many item collections, one for each character equipement, one for the shared items, etc. "Equipping" would mean moving the item from one item collection to another

2) Each character has their own inventory and you have another main shared inventory. Equipping would mean moving items from the main inventory to one of the character inventories.

Note if you plan to use UCC the only option to use will be option 2 as the character requires an inventory to equip weapons.

That's the core concept.

As for the UI that's a bit more complicated. In UIS v1.0.X there are no equipment window or drag and drop so having multiple characters makes it a bit harder to know on which character you wish to equip an item to. You could code a custom equip item action which give you a list of character names which you can press to equip... but that's probably not what you want.

This will be addressed in V1.1 (Which I am currently working on) where we will be upgrading the UI options. You'll have drag&drop, equipment windows, floating panels, filters, sorters, etc...

If you are a programmer you can of course create your own UI and I'll be happy to help you with any questions you come up with.
 
Hi desukarhu

In our system an inventory is simply a collection of items. Therefore you could make it seem like they all share the same inventory but actually all your characters have their own small inventory (with the equipped items) and then you have the "player" inventory which you share between your characters.

To design this you'll have two choices.

1)Have a single big inventory with many item collections, one for each character equipement, one for the shared items, etc. "Equipping" would mean moving the item from one item collection to another

2) Each character has their own inventory and you have another main shared inventory. Equipping would mean moving items from the main inventory to one of the character inventories.

Note if you plan to use UCC the only option to use will be option 2 as the character requires an inventory to equip weapons.

That's the core concept.

As for the UI that's a bit more complicated. In UIS v1.0.X there are no equipment window or drag and drop so having multiple characters makes it a bit harder to know on which character you wish to equip an item to. You could code a custom equip item action which give you a list of character names which you can press to equip... but that's probably not what you want.

This will be addressed in V1.1 (Which I am currently working on) where we will be upgrading the UI options. You'll have drag&drop, equipment windows, floating panels, filters, sorters, etc...

If you are a programmer you can of course create your own UI and I'll be happy to help you with any questions you come up with.

Hi,

Thanks for the reply!

Choice no. 1 seems like the best option to me. But indeed without drag & drop the whole thing seems quite cumbersome for the player. Perhaps it's best if I wait for that update, do you have any rough eta? As in days, weeks, months?

I'm an intermediate programmer, but I'm having hard time understanding most of the code in this asset, so I probably wouldn't be able to make my own UI.
 
There is no ETA yet. It will definitely take more than a month, it may take 2... or more, depending on how many options I end up adding for the UI.

If you are not using UCC and you plan to use option 1 then it should be easier to set up your own UI. Actually in the very early stages of UIS I did make a JRPG like UI with 4 characters and a shared inventory as a proof of concept. Here I found an old Gif from a year ago (Not sure why it becomes all black but you get the idea):
EquipItems_Optimized.gif


All the UI does is move the item from the main collection to one of the characters collection. And every time the inventory updates it updates the UI.

You could try to make something similar or if you want to go with an easier option with the idea of changing in later you could equip with an item action that opens a list of buttons, each pointing to a character.

Since there are a lot of things in the system I would recommend using a quick and easy solution for now and then in the future when 1.1 releases you may rework your UI functionality.

For now you could either hide equipped items in the main inventory UI or color them differently for each character. This should allow you to test the rest of your game functionality such that you do not get stuck by the UI.

I can guide you a bit on how to make the item action to equip to specific character and to color the equipped items differently for each character. If you have any questions about the code I am happy to give you some insight on why things work a certain way, and the best practices to take.
 
Alright, sounds like a lot of new functionalities, so I understand.

I'm not using UCC, the game is a 2D mixture of JRPGs and western D&D style games (neverwinter, baldurs gate).

Well damn, that example would work perfectly for me for now. Since I'm at the point in my game where my battle system works and I just need some stats and items. So making a quick and easy solution like that would be perfect.

I will dive into the code more today and see if I can figure it out. I'll ask if anything comes up.

Edit: One question came up instantly, can I add item collections at runtime? The player will have a variable amount of characters in his party and they'll all be instantiated, so that's when the collections would need to be added.
 
Yes you can, These are the functions within the inventory.

C#:
        /// <summary>
        /// Add an itemCollection to the inventory.
        /// </summary>
        /// <param name="itemCollection">The item Collection.</param>
        public void AddItemCollection(ItemCollection itemCollection)
        {
            m_ItemCollections.Add(itemCollection);
            itemCollection.Initialize(this, true);
        }

        /// <summary>
        /// Remove an itemCollection in the inventory.
        /// </summary>
        /// <param name="itemCollection">The item Collection.</param>
        public void RemoveItemCollection(ItemCollection itemCollection)
        {
            m_ItemCollections.Remove(itemCollection);
            itemCollection.Initialize(null, true);
        }

Note that the initialize(.., true), forces intialization of the item collection which removes all the items within. So you'll need to add new empty itemCollections and once they are in the inventory you can start adding the items to it.

Note that this is not something I do so there might be room for improvment. If you have any ideas on ways I could make the code easier to use for your use case feel free to ask me to add/change some things. Then I'll make the decision whether it is safe to do so or not.

Good luck with your game I'm excited to see the results :). We love to see the progress of the community so make sure to post some images/gifs in discord or in the forum!
 
So @desukarhu mentioned that items added in the itemcollection that were added at runtime were not showing in the inventory UI. That was a bug with how the itemcollection were added in the inventory.

In the inventory script replace the AddItemCollection and the RemoveItemCollection functions by the following:

C#:
        /// <summary>
        /// Add an itemCollection to the inventory.
        /// </summary>
        /// <param name="itemCollection">The item Collection.</param>
        public void AddItemCollection(ItemCollection itemCollection)
        {
            m_ItemCollections.Add(itemCollection);
            itemCollection.Initialize(this, true);
            if (Application.isPlaying) {
                EventHandler.RegisterEvent(itemCollection, EventNames.c_ItemCollection_OnUpdate, () => OnItemCollectionUpdate(itemCollection));
            }
            
        }

        /// <summary>
        /// Remove an itemCollection in the inventory.
        /// </summary>
        /// <param name="itemCollection">The item Collection.</param>
        public void RemoveItemCollection(ItemCollection itemCollection)
        {
            m_ItemCollections.Remove(itemCollection);
            itemCollection.Initialize(null, true);
            if (Application.isPlaying) {
                EventHandler.UnregisterEvent(itemCollection, EventNames.c_ItemCollection_OnUpdate,
                    () => OnItemCollectionUpdate(itemCollection));
            }
        }

Previously the itemCollection were not registering when added dynamically so adding items to them were not notifying the inventory to cache the item and refresh the UI.
This will be Fixed in the next update.

Side note: We discussed in Discord and I mentioned that creating a custom ItemCollection is a good idea for a multi-character set up.

C#:
public class MyItemCollection : ItemCollection{
  public void SetPurpose(ItemCollectionPurpose purpose){m_Purpose = purpose;}
...
}

Most fields are protected and most functions are virtual so feel free to customize things to your liking.
 
Top