How to make a CRAFTING system - UNITY TUTORIAL 2022

Поділитися
Вставка
  • Опубліковано 17 гру 2024

КОМЕНТАРІ • 98

  • @Blackthornprod
    @Blackthornprod  2 роки тому +23

    Hey everyone! Hope you enjoyed the tutorial. Here's the link to the FREE Icon PACK: www.blackthornprod.com/epic-icon-pack
    And again, thanks to Data Camp for helping us out financially by sponsoring this video.
    Unlock new career opportunities and become data fluent today! Use the link bit.ly/BlackthornprodDCJan22 and check out the first chapter of any DataCamp course for FREE!

    • @ItsMeHelel
      @ItsMeHelel 2 роки тому +2

      Any way for us to access the source files?

    • @Mr123ichkomme
      @Mr123ichkomme 2 роки тому +1

      Hey I submitted my email but can't download the pack. Please help

  • @mufelo
    @mufelo 2 роки тому +67

    Probably worth noting that relying on string recipes and order of two independent list inside of the editor will become unmanageable really quickly for any meaningful quantity of recipes. Like someone mentioned, using scriptable objects, for example, could help make actual items and recipes much nicer and you could have some inline editors to drag and drop items to recipe slots. So while it works as a starting point for anyone wanting to build a system like this, as is, it is using some bad practices that can easily become tough to manage, especially if working with a team.
    I realise this is probably just to be able to scope down the tutorial to a bite-size chunk, but it would be advisable for anyone actually building something similar to spend some time on the recipe and recipe slot logic on any system aiming for production use (or even if you have a separate person or a team working on managing the content for your game). In solo dev, you can get away with more of these types of shortcuts, but you will probably still end up hating yourself at some point.

    • @Lurch456
      @Lurch456 2 роки тому +1

      i think this could be a cool twist if done right for a rouge like game EG Magicite and Rouge lands

  • @trapshooter
    @trapshooter 2 роки тому +38

    Awesome tutorial, but I think this can be improved a lot by using scriptable objects. Each item can be a SO as well as each recipe result. On the recipe SO you can have a recipe materials array of 4 items SO. This removes the need for writing down the material in a confusing string and you are keeping a reference to an actual asset making it much more organized. The in the crafting manager you could have a list of all the recipe results and search for the one that matches the current materials order by a simple comparison. Of course the items on the canvas would also need a script that holds a reference to their correspondent item SO

  • @swoooshi.
    @swoooshi. 2 роки тому +13

    I have to admit, I will come back to this video more than once! 😂 This is such a great topic and you explained it so well. Great job 👏

  • @urbatin9355
    @urbatin9355 2 роки тому +3

    I love these specific tutorials, it really helps learning how to use the unity features to achieve different out comes, thank you!

  • @pliniomourao
    @pliniomourao 2 роки тому +6

    The only problem with the "CraftingManager" implementation, is that if you drag an item to the corner of the screen outside of a slot, it will drop the item to a slot because one of them is still the closest.
    The solution for it would be to add a variable for the minimum distance from the slot.
    Cheers

  • @martinx9027
    @martinx9027 2 роки тому +3

    I mean, yeah, this works, but it's not neither the easiest nor optimized crafting system u gonna find. I guess it's good enough for a beginner solo dev that just wants to make a 4 item crafting system with a couple of recipies, because if scaled it will be a pain in the ass. I think i saw a couple of comments point this out, but using Scriptable Objects would be so much easier, for items and for recipies. I personally like the tutorials that are the base of a system were u can build over, not the air-tight ones where you make a completely closed system for people to replicate and deal with, just because everyone games are different so people might wanna change things and poke around. Either way, great video!

  • @creativenametxt2960
    @creativenametxt2960 2 роки тому +2

    Great tutorial, I will definitely be using it in the future!
    But I think it can be improved by separating the items in the string receipe with some unique character, like ";" or "#".
    The reason for this is that currently, if I understand the code, recipes like "gearbox fire arm null" and "gear box firearm null" can't exist at the same time.
    I understand that it's not going to be a frequent problem, but I think the code shouldn't contain unexpected behavior for some weird cases if it can be avoided that easily.

  • @EdLudington
    @EdLudington 2 роки тому +1

    This is really great! I'm planning to use something similar for crafting items & spells. Thank you & cheers!

  • @ausername4meplease
    @ausername4meplease 2 роки тому +2

    Is there a way to download the source code? Hard to wrap the head around the code without seeing it. Thanks for a create video!

  • @Ethanol3310
    @Ethanol3310 2 роки тому +11

    Perfect tutorial. I tried drag and drop with the code monkey tut but it was so unnecessarily complex but this is so.simple and quick. Thank you so much Noa for this it's such. A helpful tutorial

  • @alannguyen4636
    @alannguyen4636 2 роки тому +1

    Love the tutorial but a quick question, i have it to where a crafting menu opens and closes when pressing e on an object, however even while the slots are inactive the code still reads them as still there and will just go straight into the inactive slot, is there a way to prevent this and make the object go to the nearest slot that is shown on screen?

  • @randomdotrange9528
    @randomdotrange9528 2 роки тому

    you guys rock! one of the reasons i start programming, you and brackeys! greta job thanks a lot, keep it up!

  • @gamingmonke204
    @gamingmonke204 2 роки тому +1

    I was waiting for a video like this!!
    Amazing tutorial

    • @lethn2929
      @lethn2929 2 роки тому +1

      Crafting in my view is one of those often neglected mechanics that don't get many up to date tutorials on them, weirdly I've found this to be true for proper hitscan shooting as well and looking at how to do bullet tracers, very glad he made this.

    • @gamingmonke204
      @gamingmonke204 2 роки тому

      @@lethn2929 i agree

  • @tannerboyle6540
    @tannerboyle6540 2 роки тому +1

    This is unrelated, but I think a stealth game in you're specific style would be really fun to play.

  • @TurtleGuy1527
    @TurtleGuy1527 2 роки тому

    THIS MECHANIC IS PERFECT FOR MY GAME YOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!!!

  • @kyrruo17
    @kyrruo17 2 місяці тому +1

    hello im a complete beginner i am having trouble understanding what you mean by dry(?) images i know object but why does it glow blue?

  • @RaonCreate
    @RaonCreate 2 роки тому

    Sunday HYPE!

  • @RajJaiswal538
    @RajJaiswal538 2 роки тому

    Loved the approach you have took here.
    I might've gone with something wayy more complex if I was making it myself

  • @SuperSleepyBeepy
    @SuperSleepyBeepy 2 роки тому +1

    Blackthornprod makes me feel like I live in a simulation 😂 every time I think about trying to make something, a week later he makes a video on how to do it

    • @eneaganh6319
      @eneaganh6319 2 роки тому

      You are not suposed to know that

  • @faris_diz
    @faris_diz 2 роки тому

    Love your tutorials, keep up with them!

  • @petipois28
    @petipois28 2 роки тому

    great tutorial, i agree with the comments about scriptable objects too. I will use elements of this tutorial to do a 2D cooking game. Thanks again BTP

  • @utkugokalp3179
    @utkugokalp3179 2 роки тому +7

    The way you coded the drag'n'drop system has a little issue: if you pick up the item but don't drag it onto one of the slots you are gonna expect the item to just go away but instead it is still going to choose the closest one and put the selected item in that slot. The way you should code is you should check if the distance between the selected item and one of the slots has a value equal to or smaller than a value that is predetermined, ideally set in inspector.

    • @BenL-wh4pt
      @BenL-wh4pt 2 роки тому +1

      can you write down the code there ? I am kinda bad at it ^^' . If not , i ll try this out

    • @utkugokalp3179
      @utkugokalp3179 2 роки тому +1

      @@BenL-wh4pt Sure, there you go :)
      public float slotSelectionDistance; //At the top of the script with the other variables
      //Inside Update()
      if (Input.GetMouseButtonUp(0))
      {
      if (currentItem != null)
      {
      customCursor.gameObject.SetActive(false);
      Slot selectedSlot = null;
      foreach (Slot slot in craftingSlots)
      {
      float dist = Vector2.Distance(Input.mousePosition, slot.transform.position);
      if (dist < slotSelectionDistance)
      {
      selectedSlot = slot;
      break;
      }
      }
      if (selectedSlot != null)
      {
      selectedSlot.gameObject.SetActive(true);
      selectedSlot.GetComponent().sprite = currentItem.GetComponent().sprite;
      selectedSlot.item = currentItem;
      currentItem = null;
      }
      }
      }
      If the code has any typos lemme know and I'll edit it :)

    • @BenL-wh4pt
      @BenL-wh4pt 2 роки тому

      @@utkugokalp3179 what a legend you are , thx a lot , ill let you know if it work well ^^

    • @utkugokalp3179
      @utkugokalp3179 2 роки тому

      @@BenL-wh4pt No problem :)

    • @Den69699
      @Den69699 2 роки тому

      @@utkugokalp3179 hi i tested it and it doesnt work correctly what do we have to set for
      slotSelectionDistance

  • @Hiren24
    @Hiren24 2 роки тому +2

    Can anyone pls tell that what all components are there in result slot and what you have written in index and item in slot script of result slot as my project is not working and also can anyone tell what have a done wrong just the result par is not working except that every thing is working pretty good plss someone help:(.

  • @MikaKC
    @MikaKC 2 роки тому

    Awesome tutorial ;) Definitely gonna use this for my upcoming R.P.G! Thanks again for this :)

  • @taisublack2599
    @taisublack2599 2 роки тому +2

    Thank you so much Noah for you content which is extremely useful for me, thank you so much for your tutorials !

  • @yakanashe
    @yakanashe 2 роки тому +2

    will you also make the other polls? eg Card game

  • @dankel317
    @dankel317 2 роки тому

    exactly what i needed right now!

  • @uranus862
    @uranus862 2 роки тому

    Love the video, keep it up!

  • @DaniloMatos13
    @DaniloMatos13 2 роки тому

    Thank you! Keep up the good work!

  • @vovinlonshin3708
    @vovinlonshin3708 2 роки тому

    nice system. thank you for all your hard work

  • @paytonpattison3463
    @paytonpattison3463 2 роки тому

    I’m about to get into making a unity game, would you be able to make a more recent tutorial? Like how to do x. Anything would help!

  • @brandonjacksoon
    @brandonjacksoon 2 роки тому

    Thank you! Awesome tutorial!
    Im sure it will be useful for me))

  • @DeepSpaceIndustriesLOL
    @DeepSpaceIndustriesLOL 2 роки тому

    Wish I could make art like yours

  • @deezdev9540
    @deezdev9540 2 роки тому

    I gotta love your videos :3

  • @greenheart5369
    @greenheart5369 2 роки тому

    Great video!

  • @taisublack2599
    @taisublack2599 2 роки тому

    The also an idea about next tutorial could be about, I was thinking about weapon system where you are able to improve your weapon increase the damage of bullets or something like also I had in my mind tutorial about sword attack system like Idoz made in his game called archvale or even explain how to make a shop or quest systems.

  • @kackbiene
    @kackbiene 2 роки тому +1

    That Video is very helpfull thank you so much!!!❤❤

  • @fabriciobidegain7678
    @fabriciobidegain7678 2 роки тому

    Hello. I wanted to know if you could explain to me how to create a weapon system and metal slug type vehicle handles in game maker 2 thanks

  • @mcincal6810
    @mcincal6810 2 роки тому +1

    Please still do the card game tutorial!

  • @fulgerx9865
    @fulgerx9865 2 роки тому

    Thank you for the tutorial

  • @samidev4122
    @samidev4122 2 роки тому

    Hey Noa Bro if you have time please make tutorials on card making games like you jave created at hallowan

  • @kaisonlee71
    @kaisonlee71 2 роки тому

    Thanks for the video. I was really needing it. But currently I am facing a problem which is that how to collect the crafted item into the inventory. If someone know it, could you please give me suggestion? Thanks

  • @GameDevForLife
    @GameDevForLife 2 роки тому

    Good video
    These video with a lot of code it's my favorite type video

  • @sirseal2554
    @sirseal2554 2 роки тому

    you should make a game about being a hummingbird who has to use flowers to refuel

  • @shibuyajin_music
    @shibuyajin_music 2 роки тому

    lil bro is using strings AND looping through strings AND relying on same index to find the result on a different list NAAAAAAH AINTNOWAY
    youtube never disappoints with the goofy ah codes

  • @toastgames9028
    @toastgames9028 2 роки тому

    Great tutorial just one question. Does it work with your inventory tutorial?

  • @bittenhare4493
    @bittenhare4493 2 роки тому

    Damn you made this video quickly

  • @inferno3471
    @inferno3471 2 роки тому

    Thank you my teacher

  • @TheDevJRs
    @TheDevJRs 2 роки тому

    Very good tutorial

  • @megunay
    @megunay 2 роки тому

    When I tried "public Item item;" I am having an error on Item CS0246 how can I solve this?

  • @GloriousYouTube
    @GloriousYouTube Рік тому

    How could I make this work with your inventory video?

  • @brycegiom.belencio3541
    @brycegiom.belencio3541 2 роки тому

    Inventory System for the next video please 🙏🙏🙏

  • @pappyto
    @pappyto Рік тому +1

    why cant i see anything on my game, but i can see everything in my scene

  • @ItsMeHelel
    @ItsMeHelel 2 роки тому

    Is there any way for us to access the initial resource?

  • @caravanhati9202
    @caravanhati9202 Рік тому

    can anyone help me, i want to move items from inventory to crafting

  • @노성엽-y2k
    @노성엽-y2k 2 роки тому

    What if I need more than 1 number in a combination?

  • @risheekbharadwaj6387
    @risheekbharadwaj6387 2 роки тому

    How can I access these codes ? For reference purpose ?

  • @zeyanramzan1551
    @zeyanramzan1551 2 роки тому

    Next plzz make the Card game

  • @mykytabielokon
    @mykytabielokon 2 роки тому +4

    In my opinion, the worst thing about this tutorial, or the overall approach to organising a crafting system this way, is using strings to store the recipes. Not only is it susceptible to spelling errors but also the very assumption that the player would drag and drop the items in the order described in the recipe is naïve because the string-building process is dependent on the order of the resources in the slots instead of what they actually are. Wouldn't it make much more sense to check the type and the quantity of the resources in the slots and then loop through all the existing recipes and check if the types and quantities of the resources match any recipe?
    Not to mention that all the logic runs in the Update methods where, to make things worse, you're using GetComponent methods.
    I would've added a Craft button or something that would call a method that gets all the resources in the slots, adds them to a class or a struct, passes it to another method that determines if anything can be crafted from the received resources and if so returns the crafted item.

    • @lethn2929
      @lethn2929 2 роки тому +1

      I might investigate the code myself as well and see what's out there that's up to date, I think you do have a point about his use of strings and GetComponent. I realise strings are generally frowned upon when it comes to code efficiency because of the searches you have to do but with GetComponent code it can be done efficiently if it's setup the right way. Seems like it might be a good idea for BlackThorn to do an update video on this just to issue some corrections, if not, then people can post corrections in the comments page.

  • @deveshsingh0904
    @deveshsingh0904 2 роки тому

    Can anyone of you please Guide That How do I complete my project very quickly. For example I was working for 1years in Game Development And Made a Ludo(Dummy)Game And Now working on a Project Of Chess Game for Last 7 months of Time with 4hrs a day But I have Done A little Of work Till Now But When I was Making I taught that it this or this work is so simple Just take up only a few minutes But It take 3 -6 Days but even I left something Out Can Any one of You Have the solution of this If yes Then please suggest me Because There are Better experience Game developer Than me

  • @rusikboss5077
    @rusikboss5077 2 роки тому

    Очень понравилось. Жду с нетерпением следующие уроки👍

  • @darkflame2848
    @darkflame2848 2 роки тому

    How to make 2d portal
    2d running game like subway surfer
    😀

    • @lethn2929
      @lethn2929 2 роки тому +2

      Hey, if you're looking to just make a general teleporting mechanic, it's actually quite straightforward, do a collision check on whatever your 'portal' gameobject is as your player is running through, then use something like transform.position = portal.transform.position to instantly move your player there once the player collides with the portal gameobject. You can also use this method if you're wanting to teleport a player with the mouse, just adapt the code to a raycast hit position. The way I would do it is attach a script to the portal itself and keep track of the connected portal you want the player to go to that way.

    • @darkflame2848
      @darkflame2848 2 роки тому

      @@lethn2929 thanksss a lot brooo , am newbie so....

  • @fuzzy-02
    @fuzzy-02 2 роки тому

    Nice tutorial but was too fast, by that I mean that when I understand the point at hand, you'd be in the middle of the next

  • @lgmations
    @lgmations 2 роки тому

    please slow down your speed. I cant understand anything.

  • @pappyto
    @pappyto Рік тому +1

    nothing is working for me bro be more specific

  • @B2UENUKE
    @B2UENUKE 2 роки тому

    AND FREEDOM

  • @omegacrimson2809
    @omegacrimson2809 11 місяців тому

    this guy was capping the capitalization DOES matter

  • @kaasronald3623
    @kaasronald3623 2 роки тому

    I clicked on this to see how you'd handle recipes but this method isn't great. It way too strict. the order will need to match. So you could do woodwoodstone but not woodstonewood etc. You also can't reorganize your recipes easily due to 2 lists that must match the order in the inspector. or let alone change the name of an ingredient.

  • @galibrabat4237
    @galibrabat4237 2 роки тому

    NEXT IS CARD GAME

  • @Jdudeo1
    @Jdudeo1 2 роки тому

    Hello

  • @KeyboardKrieger
    @KeyboardKrieger 2 роки тому +5

    Normally I like your content, but this recipe system just gave me cancer. Working with strings when not necessary is something everybody should avoid at all costs.
    Please next time look up beforehand how other devs handle your topic. Giving items the recipe in Form of an array of other items, or make a recipe containing the item to create and an array of items needed would be two way better options.

  • @tronda-bomba
    @tronda-bomba 2 роки тому +1

    This is 70 comment so i detroyed 69

  • @latip9569
    @latip9569 24 дні тому

    yg bener aja mas

  • @AlawiDenGhosty
    @AlawiDenGhosty Рік тому

    doesnt work at all
    nothing u did works at all, show the whole SCREEEEEENNNN AND SHOW EVERYTHINGGG YOU DOOOOOOOOOOOO WHY SKIP STEEEEEPPSSSSS AND ZOOOOM IN ON EVERYTHINGGGGG

  • @iknowcturne7362
    @iknowcturne7362 2 роки тому +1

    Talk normally holy shit

  • @AlawiDenGhosty
    @AlawiDenGhosty Рік тому

    Rare L, this isnt good

  • @Den69699
    @Den69699 2 роки тому

    I made a bit of a difference so you get the new item ... and the dragging does things better any questions ask
    Crafting manager :
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    public class CraftingMan : MonoBehaviour
    {
    private Item currnetitem;
    public Image cursorCus;
    public Slots[] craftingslots;
    public GameObject[] result;
    public List itemlist;
    public string[] recipe;
    public Item[] repiperesult;
    public Slots resultslot;
    bool isitin = false;
    private void Update()
    {
    if (Input.GetMouseButtonUp(0))
    {
    if (currnetitem != null)
    {
    if (!isitin)
    {
    currnetitem = null;
    cursorCus.gameObject.SetActive(false);
    return;
    }
    if (isitin)
    {

    Debug.Log(isitin);
    cursorCus.gameObject.SetActive(false);
    Slots nearestslot = null;
    float shortdistance = float.MaxValue;

    foreach (Slots slot in craftingslots)
    {
    float dis = Vector2.Distance(Input.mousePosition, slot.transform.position);
    if (dis < shortdistance)
    {
    shortdistance = dis;
    nearestslot = slot;
    }
    }
    nearestslot.gameObject.SetActive(true);
    nearestslot.GetComponent().sprite = currnetitem.GetComponent().sprite;
    nearestslot.GetComponent().SetNativeSize();
    nearestslot.item = currnetitem;
    nearestslot.GetComponent().color = Color.white;

    itemlist[nearestslot.index] = currnetitem;
    currnetitem = null;
    Checkforrecp();
    }
    }
    }
    }
    void Checkforrecp()
    {
    resultslot.gameObject.SetActive(false);
    resultslot.item = null;
    string currnetrecpiestring = "";
    foreach(Item item in itemlist)
    {
    if (item != null)
    {
    currnetrecpiestring += item.name;
    }
    else
    {
    currnetrecpiestring += "null";
    }
    }
    for (int i = 0; i < recipe.Length; i++)
    {
    if (recipe[i] == currnetrecpiestring)
    {
    resultslot.gameObject.SetActive(true);
    resultslot.GetComponent().sprite = repiperesult[i].GetComponent().sprite;
    resultslot.GetComponent().SetNativeSize();
    resultslot.item = repiperesult[i];
    result[i].SetActive(true);
    }
    }
    }
    public void INIT()
    {
    isitin = true;
    }
    public void OFFIT()
    {
    isitin = false;
    }
    public void OnclickSlot(Slots slot)
    {
    slot.item = null;
    itemlist[slot.index] = null;
    slot.gameObject.SetActive(false);
    Checkforrecp();
    }
    public void OnmouseDOwnItem(Item item)
    {
    if (currnetitem == null)
    {
    currnetitem = item;
    cursorCus.gameObject.SetActive(true);
    cursorCus.sprite = currnetitem.GetComponent().sprite;
    cursorCus.GetComponent().SetNativeSize();
    }
    }
    }

  • @노성엽-y2k
    @노성엽-y2k 2 роки тому

    What if I need more than 1 number in a combination?