Search Unity

Question Crafting system using current inventory system?

Discussion in 'Scripting' started by JamieA806, Jun 5, 2023.

  1. JamieA806

    JamieA806

    Joined:
    Mar 30, 2023
    Posts:
    2
    Hi everyone

    Up to this point, I've followed Coco Code's tutorial how to make a drag and drop inventory system, and I have created my own script to be able to acquire items by pressing a key while inside of a trigger radius, so I can do stuff like search drawers and acquire items in my game.

    This part works fine, and is fully finished, except I also need to be able to craft items. In my GUI, I have 3 grids: one for general items slots, one for crafting slots, and one craft output slot. I also have made a scriptable object for every item in my game, including ones that are made by crafting.

    All I need is to check if the required items are present in the craft slots, and when they are, create the item in the output slot, and destroy the items in the craft slots. I just simply have no idea how to do that, because there isn't a good tutorial for this specific functionality I want.

    I should mention also my game is very low scope and only has two crafting recipes in the whole thing.
    Let me know if there's any good solutions or guides for this :)
    I can also provide my existing code if it's needed
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    That's like saying "I only need a car to drive to church on Sunday."

    You still need a full complete functioning insured registered car, not just a small sub-fraction of it.

    First, design the system you want.

    Second, implement the system iteratively, perhaps going back to the design.

    Here's my cheatsheet for these crazy things:

    These things (inventory, shop systems, character customization, dialog tree systems, crafting, etc) are fairly tricky hairy beasts, definitely deep in advanced coding territory.

    Inventory code never lives "all by itself." All inventory code is EXTREMELY tightly bound to prefabs and/or assets used to display and present and control the inventory. Problems and solutions must consider both code and assets as well as scene / prefab setup and connectivity.

    Inventories / shop systems / character selectors all contain elements of:

    - a database of items that you may possibly possess / equip
    - a database of the items that you actually possess / equip currently
    - perhaps another database of your "storage" area at home base?
    - persistence of this information to storage between game runs
    - presentation of the inventory to the user (may have to scale and grow, overlay parts, clothing, etc)
    - interaction with items in the inventory or on the character or in the home base storage area
    - interaction with the world to get items in and out
    - dependence on asset definition (images, etc.) for presentation

    Just the design choices of such a system can have a lot of complicating confounding issues, such as:

    - can you have multiple items? Is there a limit?
    - if there is an item limit, what is it? Total count? Weight? Size? Something else?
    - are those items shown individually or do they stack?
    - are coins / gems stacked but other stuff isn't stacked?
    - do items have detailed data shown (durability, rarity, damage, etc.)?
    - can users combine items to make new items? How? Limits? Results? Messages of success/failure?
    - can users substantially modify items with other things like spells, gems, sockets, etc.?
    - does a worn-out item (shovel) become something else (like a stick) when the item wears out fully?
    - etc.

    Your best bet is probably to write down exactly what you want feature-wise. It may be useful to get very familiar with an existing game so you have an actual example of each feature in action.

    Once you have decided a baseline design, fully work through two or three different inventory tutorials on Youtube, perhaps even for the game example you have chosen above.

    Breaking down a large problem such as inventory:

    https://forum.unity.com/threads/weapon-inventory-and-how-to-script-weapons.1046236/#post-6769558

    If you want to see most of the steps involved, make a "micro inventory" in your game, something whereby the player can have (or not have) a single item, and display that item in the UI, and let the user select that item and do things with it (take, drop, use, wear, eat, sell, buy, etc.).

    Everything you learn doing that "micro inventory" of one item will apply when you have any larger more complex inventory, and it will give you a feel for what you are dealing with.

    Breaking down large problems in general:

    https://forum.unity.com/threads/opt...n-an-asteroid-belt-game.1395319/#post-8781697
     
    orionsyndrome likes this.