Repost - Inventory & Items
The second major part of my responsibilities was building the inventory and item system. It was a fun challenge that required a mix of scripting, UI design, and figuring out how to make the system both flexible and easy to expand in the future. Here’s how it all came together, step by step.
Starting with the Basics
The first step was to create a system where the player could collect items and store them in an inventory. At its most basic level, this required:
- Item Definitions:
- I created an
ItemData
ScriptableObject to define each item. This included fields for:itemName
(the name of the item).description
(a brief description of what the item does).itemIcon
(a sprite to represent the item in the inventory).isKeyItem
(a flag for items that are important for progression).
- Using ScriptableObjects was a great choice because it allowed me to easily create and manage items without hardcoding anything.
- I created an
- Player Inventory:
- I wrote a
PlayerInventory
script to store a list of collected items. - The script included methods to:
- Add items to the inventory.
- Check if the inventory contains a specific item.
- Remove items if needed (although we don’t use this often yet).
- I wrote a
- Item Pickup:
- For interactable items in the world, I added an
ItemPickup
script. This script would detect when the player interacted with an item, add it to the inventory, and destroy the object in the scene.
- For interactable items in the world, I added an
This basic setup worked, but it was missing one big piece: the UI.
Building the Inventory UI
Once the inventory system itself was working, I moved on to designing a simple UI to display the player’s collected items. Here’s how I approached it:
- UI Layout:
- I created an Inventory Panel with a grid layout to display item slots.
- Each slot was represented by an
ItemSlotPrefab
, which included:- An
Image
component to show the item’s icon. - (Optional) A
Text
component to show the item’s quantity, though we don’t track quantities yet.
- An
- Connecting the UI to the Inventory:
- I updated the
PlayerInventory
script to notify the UI whenever an item was added or removed. - The
InventoryUI
script handled updating the item slots, populating them with icons from theItemData
ScriptableObject.
- I updated the
- Testing and Refining:
- This was a lot of trial and error. For example, I had to fix issues with overlapping UI elements and items not being cleared correctly when the inventory updated.
- I also added some placeholder styles to make the UI look cleaner and easier to read during testing.
Making the System Modular and Reusable
After getting the basics working, I focused on making the system flexible and reusable for other parts of the game. This included:
- Scriptable Item Pickup:
- Instead of hardcoding each item pickup, I made the
ItemPickup
script reference anItemData
ScriptableObject. This way, I could easily assign different items to pickups in the Inspector without writing new code.
- Instead of hardcoding each item pickup, I made the
- Inventory Interaction:
- I added an event system so other systems (like dialogue or quests) could check the inventory.
- For example, the quest system can now check if the player has a specific item before progressing.
- Preparing for Expansion:
- I designed the inventory system with future mechanics in mind, like using consumable items or equipping gear. These features aren’t implemented yet, but the foundation is there to add them later.
Challenges and Lessons Learned
There were a few tricky parts along the way:
- UI Updates:
- Making sure the inventory UI updated correctly when items were added or removed took longer than expected. I learned a lot about Unity’s UI system and the importance of testing changes in different screen resolutions.
- Balancing Simplicity and Flexibility:
- I wanted the system to be easy to use for our demo but also flexible enough to expand later. Using ScriptableObjects for items and events for inventory interactions helped strike this balance.
- Testing:
- Debugging the interaction between the item system and other parts of the game (like quests) required a lot of playtesting. I found a few edge cases where items wouldn’t behave as expected, but fixing these helped make the system more robust.
Final Thoughts
The inventory and item system feels solid now. It’s simple enough for the current scope of the game but has room to grow as we add more mechanics. I’m especially proud of how modular it is—we can easily add new items, pickups, and inventory interactions without rewriting code.
Looking ahead, I’d like to:
- Add support for consumable items and equipable gear.
- Improve the inventory UI with better visuals and maybe some animations.
- Make the item system interact more dynamically with other game mechanics, like puzzles and combat.
Get NeoNoir
NeoNoir
A CyberPunk Detective Game
Status | Prototype |
Authors | cornbob777, Aykou, somedudenameprophet, "Dark" |
Genre | Adventure |
Tags | Cyberpunk, Mystery |
More posts
- Repost - DialogueDec 19, 2024
- The first puzzleDec 19, 2024
- NeoNoir Devlog 11/5/24Nov 05, 2024
- Ayman -BioOct 23, 2024
- Bio - Dean/DarkOct 18, 2024
- Sam's Bio and Concept SketchesOct 17, 2024
- Roberts BioOct 04, 2024
Leave a comment
Log in with itch.io to leave a comment.