Weapon Inventory and how to script weapons.

Hey guys so this post is going to be a long one so if you don’t have to time for it or aren’t interested I would suggest skipping! Thanks for any help and your time spent trying to help!

So I want to make a gun/weapon system I am a complete beginner trying to understand C# and the best practices with it. The weapon system should have an inventory to work with like an primary and a secondary type not really an inventory I tried to do that following an brackeys video it worked but didin’t really fit the way I want the system to be. What I want is a system where you can pick your weapon at the start and then in the game you can pickup ammo types for weapons like rifle ammo for all rifle type guns and pistol ammo for all pistols and etc. I want to also add multiple weapon types easy to make if I wanted to make a shotgun I could use a base weapon script and add whatever that needs to be added to make a shotgun I just don’t know where to start. Would I start with an inventory or a weapon base class or what I’ve read a lot of forums but not a lot of results. Thank you guys so much for your time and I would be very glad if you can explain so that I can learn instead of copy and pasting a code or something like that, have a great rest of your day!

This sounds like an inventory that supports stacking. Look around for tutorials that do this, or else take an existing tutorial’s code and add the notion of quantity of each item.

Remember, you will NEVER be able to pound such a system out all in one go. That’s not how engineering works.

Instead, start from an existing functional inventory that does some part of what you want and iterate additional features onto it.

Sounds g

Sounds great man thanks for the advice, the problem when I started to develop games was just trying to make big game elements like when I was still learning and trying to make a system that was so hard for me to do instead of starting small any how I will try that I watched tutorials but It just doesn’t give me a framework for say I can understand the way they do it but not have to implant it if that makes any sense thanks for your reply though!

You’re welcome of course.

One thing you could try to really get a “feel” for what happens in this case is make a simple script that is just one cell of your inventory. Put this into a script that you can access through an “inventory API” that does certain things to a cell.

These functions might be:

“Set the type of item”
“Query the type and quantity of item in this cell”
“Add 1 item to this cell.”
“Add N number of items to this cell.”
“Remove N item from this cell.”

Then you can have properties in the cell that say “I can hold only 1 item” or “I can hold up to 30 items” inside a particular cell.

Make some test buttons on a screen to do the above items, and also print out what’s in the cell.

If you get that going you have done a huge amount of the work.

After that you need the aggregate collection of these things. That would have its own API, perhaps things that say:

“Give me a blank cell, I have something for you” (you get a cell, you call the above set type, set quantity)
“Find me a cell with N number of items of type X”

That’s breaking the problem down into steps.

1 Like
Old School RPG Inventory List
Creating a shop and backpack inventory systems
Need some help for item inventory system
error CS1022: Type or namespace definition, or end-of-file expected
Adding Loot Box/Gacha Items to Inventory?
Refinery System
Costmeci / character creation And costum weapons in pixal art 2d top/down.
Best Practices - Data Structures for "Market" System
Customising player characters
Help with a inventory system c#
Inventory UI Hotbar
Object reference not set to an instance of an object
Array element returning null, but has data is assigned
NullReferenceException: Object reference not set to an instance of an object
Inventory system: prefab and scriptable object
Getting 'Null Reference' error while working with Array in Unity
Make a 2D character swap mechanic?
I want to create a text based inventory
Feedback on a Shop Script I Wrote
How to add random items to Inventory dynamically?
How to change the image of an instantiated prefab in the UI by mouse click on a game object in the s
look the error is : Assets\scripts\InventorySystem.cs(84,25): error CS0839: Argument missing
Fashion Media App
Compare Tag not working as intended?
How to load scriptable objects during runtime in build
how to deal with equipment (armor, weapon)?
2D non-animated avatar creator?
how can i solve error CS1002
i`m trying to make a inventory i`m trying to make it so i don`t need to drag the slots
Define a Var depending on value from another Var
Issue with toggles in C# Unity
I don't want stacking in my inventory slots
loot system with Scriptable Objects
Scrolling Item Bar like Legends Arceus?
Best practices for holding Inventory UI / GameObjects / etc
Enum & inventory
Help on making an inventory similar to SCP:CB!
I've made an inventory drag and drop screen but when I press play how can I open it and close it
inventory question
Script to reference GameObject not working on Mobile test?
Ideas on how to create a WoW-like ability system
Inventory Item Stacking Problem
Any method to hide objects is only affecting the prefabs and not the active instances
Setting the parent of a transform which resides in a Prefab...
Trying to make a Pokemon clone, not sure if my implementation is bad practice?
Help with character creation
How should I Manage my elements?
Syntax Error, ',' expected
Inventory Manager
Need help with Inventory Script
Persistent UI, Data Sync, and Performance Issues While Building a Restaurant Menu Experience in Unity
How to use all of the items in 1 script
Using a ScriptableObject Based Inventory System and a FSM to Trigger Interactions
Hiding inventory bug
Scripts not awakening on Game Object
How To Set an Object That References It?
Multiple different playable characters
How to equip my character with more than 100 Armor?
How to programmatically set first selected item in Event System?
The logic behind equipping item models
How would you approach the creation of a versatile inventory system similar to Pokémon's?
HELP! How to fetch data from items?
Scriptable Object and Data Base
How to move items around in an inventory
how to make different types of scriptable objects?
How can I call a function from a nearby gameobject's script?
Menu Heavy Game - How to handle the data
Want to use interface for lootable items but don't know where to start
Best inventory system type for end user?(~grid vs list)
Object System / How to manage unique abilities
Hello guys, i need a little help in my code.
How to correctly insert new objects into the script
Checking for Certain Game Objects in a list with a Tag
How to Unhide a sprite and Hide it with the same button?
procedural generated voxel characters?
Move an item to a chest by clicking in its UI
In game computer shop system
Player Inventory Problems
Two Errors and a Warning.
Question on a (more or less) complex inventory/item system
Editor friendly system for item management and creation advice
How do i make an item highlight when i look at it?
Football stadium customisation
SIMPLE displaying static variables workaround
In-game "notifications" by checking if specific bools are true/false
Inventory System for Survival Game
Dealing with multiple types of items for an inventory
Creating a 3D Inventory system with swapping objects.
InventoryCell issue for inventory system
Inventory (Kind of)
Clearing and recreating Lists for Inventory System.
Instantiating Scriptable Objects
Can't change sprite of game object in script
Change Multiple Character Sprites
Build and run does not the same thing as in the editor
Best approach for multiple inventories dealing with a base Item class?
Vehicle selection menu with multiple cars at once
Creating items with random stats
Inventory Description/Name 2D
Action coming off as null
Need help fixing a level system script
Remove item from inventory
Dragging a game object into a UI hotbar slot
GameObject set active not working in shop system
Issues making a daily hat store selector
Inventory Ui not working as expected
Get variable from other script with unknown name
How to make object in Canvas space themself and center on a line
Trying to add coins to user inventory after successful register
I have a problem with my saving & loading system
How can I Write Inventory System?
Trying to update field but unable to?
Inventory Managment/System for a factory game
Why isn't can't I set this bool correctly from an array & for loop?
Bottom left anchor changes child object position?
Elements in list become null after I try to print them
Bugs with character controller and Inventory System
How do a VR program - world building like game or virtual world?
Shared rig between skinnedmeshrenderer mannequin and clothes
How to check for certain words in string?
Sprite Library, Drag and Drop to replace labels sprites
Finding all Types of a Class within the Assets
Unity 2d Drag system
Character changing clothes
Create inventory from folder
How to create a good upgrade system
List Not working
Item still in list after deleting

That sounds great I will try to make something like that and let you know once I put it all together once again thanks for the ideas!

1 Like

I’ve been working on the inventory API and its going great got multiple void functions to get cell information to check if it is occupied or which item id is in said slot. Now I got the thinking about how to make the weapon do you have any ideas I can easily make a weapon system but just haven’t thought about the framework do you have any ideas on that?

Not really specifically but I would go about it the same way… components and parts go into a weapon. Think about the last X games you have played that had a weapon system you liked, and think about what the API might have been for those games. That’s how to digest it really.