Grid Inventory in Unity Tutorial Tile based inventory in Unity

Поділитися
Вставка
  • Опубліковано 14 лип 2024
  • Assets: drive.google.com/file/d/1TX8Y...
    0:00 - Intro
    1:07 - Grid Setup
    4:30 - Item Grid
    18:28 - Storing Items on grid
    30:10 - Click to pick up item and move item
    35:21 - Visualize of item drag
    37:41 - Item size and item scriptable object
    51:06 - Item occupy multiple tiles
    56:40 - Item out of bounds check
    1:03:15 - Handling Overlapping objects
    1:15:47 - Object highlight
    1:40:17 - Multiple inventory grids
    1:41:41 - Insert item Add item to inventory
    1:51:46 - Rotating item
    2:00:07 - Addendum
    In this episode of unity tutorial, me Greg will be making a grid inventory. Just like in games like Escape From Tarkov, Diablo or Path of Exile. This is tutorial how to make grid inventory in unity. How to make grid inventory from Path of Exile. How to make Grid inventory like in Diablo. How to make inventory like in Escape from Tarkov. Inventory from EFT how to make in unity. How to make in unity Grid inventory. Tile inventory in unity. How to make Tile inventory in unity tutorial.
    Patreon: www.patreon.com/user?u=28674164
    Ko-fi: ko-fi.com/gregdevstuff
    Twitter: / gregdevstuff1
    Discord: / discord

КОМЕНТАРІ • 277

  • @GregDevStuff
    @GregDevStuff  2 роки тому +40

    CORRECTIONS AND COMMENTS (will be added in course of discovering mistakes and errors) (If you stuck join discord or comment!)
    This system is designed to be used with fixed resolution! Make sure you set the fixed resolution in the GameWindow and on the canvas.
    25:46 instead of gridSizeWidth and gridSizeHeight, you need to use tileSizeHeight and tileSizeWidth! On 29:25 you can see correct code for this part!
    Sorry for very sloppy editing in this episode, my computer can't handle videos of this size. So there is a lot of small misstypos being left because it was very hard to edit anything in this tutorial.

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

      i didint see this and i was going crazy

    • @alphaw1gaming85
      @alphaw1gaming85 Рік тому +3

      Even if a change to tileSizeHeight and tileSizeWidth, the item is instantiated in the position 4 -4 with scale 1.45.
      The only way a figure to fix was change this piece "position.y = - (posY * tileSizeHeigh + tileSizeHeigh / 2);" to this "position.y = - (posY * tileSizeHeigh / 2);"

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

      I think I missed something in video, but anyway. On section "Item size and item scriptable object" I couldn't place created item because tileGrid could not be spotted (behind created item) because in Item prefab you should turn off 'Raycast Target'.

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

      @@star_c4313 You definitely mised that part, but good job figuring it out! :)

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

    An amazing job with this tutorial! Most tutorials out there are confusing and skip over some details, but you went in depth. Thank you very much!!!

  • @gregorycatellani2182
    @gregorycatellani2182 Рік тому +7

    An amazing tutorial! Easy to follow, in detail, good explanations. You saved me a lot of time, sweat and tears.

  • @perico17
    @perico17 Рік тому +8

    Wonderful tutorial!! For anyone wondering, if you rotate the item without moving the mouse, the highlight might not rotate at first. You can fix it by replacing "if(oldPosition == positionOnGrid)" with "if(oldPosition == positionOnGrid && !Input.GetKeyDown(KeyCode.R))" or whatever key you assigned to rotation in HandleHighlight().

  • @seangailey9035
    @seangailey9035 Рік тому +14

    I see a lot of questions regarding the UI scaling via a CanvasScaler. There's an easy solution to this. In ItemGrid's GetGridPosition(), you need to adjust the tileGridPosition x/y by the root canvas' scale factor. Adjust these two lines (rootCanvas is set to the root Canvas with the CanvasScaler component):
    tileGridPosition.x = (int)(positionOnTheGrid.x / (tileSizeWidth * rootCanvas.scaleFactor));
    tileGridPosition.y = (int)(positionOnTheGrid.y / (tileSizeHeight * rootCanvas.scaleFactor));
    Great video!

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

      But how do you scale the Icons?

    • @jellomello2683
      @jellomello2683 11 місяців тому +2

      MAH MAN i was looking for over 3 Hours to solve this and then went back to the comments here to find your comment. Thanks for saving my sanity tho XD

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

      @@jellomello2683 Glad it helped!

    • @user-sp3dh4ch3o
      @user-sp3dh4ch3o 5 місяців тому +2

      @@niklasschiedeck same way, icon rectTransform localScale multiply by rootCanvas.scaleFactor

  • @AllDayBikes
    @AllDayBikes Рік тому +13

    It took me about 3 weeks on and off ( maybe 15-20 hours total) to implement this with changes I desired as I went. I learned a lot.
    Thanks so much for making this tutorial man!

  • @topher-two-four
    @topher-two-four 8 місяців тому

    This tutorial that you created is well-explained and easy to follow.
    Thank you for providing this to the public, it's extremely helpful!

  • @_Elvano
    @_Elvano 2 роки тому +12

    Thankyou so so much you saved me so much time and suffering trying to find this you defiantly deserve more recognition

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

      Have you finished the video? If yes any feedback?

  • @Aproppo
    @Aproppo 2 роки тому +8

    This is an incredible tutorial! It's elusively simple and really well coded all things considered. I've always wanted to make a grid inventory system but had no clue how to even start and this made it look really easy! You're a blessing to the indie game development scene!

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

      Thank you. If you want to help, please spread the word around on social media! Consider checking my other tutorials.

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

    Seriously a great way to do the Turorial everything step by step and easy to understand I learned a lot during ur Video and I am truly grateful for it.

  • @adammed8667
    @adammed8667 8 місяців тому +4

    best part is at 28:15 when he just said: "Ha????". I couldn't stop laughing, it was so unexpected, and expected at the same time. Great Video regardless. Keep the good work up!

  • @aryavatan
    @aryavatan Рік тому +2

    Amazing tutorial! After searching for a while this was exactly what I needed to help me get started with this system. It's very easy to extend it after you finish your tutorial to fit your games needs. Thank you so much!

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

      Love you! Check the stream if you have time! And other tutorials! Post online so people will learn about this!

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

    Incredible detailed & well made video. I followed the whole tutorial and everything worked.
    Great job and a very good foundation!

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

    Greate tutorial! I am happy I followed it because I am a novice at Unity and it helped me greatly!

    • @GregDevStuff
      @GregDevStuff  2 місяці тому

      Thank you. Join discord, and check pinned comments in help it have expansion for this system.

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

    Amazing video. Thank you for taking the time to make something so detailed.

  • @Jocktor
    @Jocktor 2 роки тому +8

    One of the best tutorials i have followed along with online. I learned so much from how you do things, keep up the great work. I will be checking out more!

  • @ragnarzdeveteria
    @ragnarzdeveteria 11 місяців тому +5

    This tutorial was so good i didn't wanted it to end! I noticed there's not much info about setting up inventories like SCUM, Escape from Tarkov, etc. so I hope to learn more tricks to replicate them.
    Thank you so much!

    • @GregDevStuff
      @GregDevStuff  11 місяців тому +2

      Spread the word about the channel my dude! :)

  • @LAB_RAT_
    @LAB_RAT_ Рік тому +3

    Amazing tutorial, sets up a solid foundation for a project and everything is explained in detail. Although the content is difficult, you explain it so well that the video is easily digestible for a beginner like me .Thank you so much for providing this content for free and for giving an example of what a prefect tutorial looks like !!

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

      I wouldn't call it perfect. There is some concepts left unexplored, and some systems are actually can be done way better. Thou it should provide you with foundation you can expand upon! :)

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

      @Greg Dev Stuff I really enjoyed you showing everything you do, I found myself doing a lot less troubleshooting in your tutorial than I usually do in other tutorials, so thanks for that, looking forward for new tutorials :D

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

    Thank you so much for this tutorial, it's gonna be a great help for my first game!

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

    This is one really amazing tutorial. Much better than most of other tutorials that just copy paste 200 lines of code and explain nothing.

  • @gaffeOS
    @gaffeOS Рік тому +2

    Thanks for this, exactly what I needed. I tried using some GitHub frameworks for setting up a grid inventory, but found modifying them through their countless interface methods was more trouble than it was worth. Now I set up this grid, and I know exactly how it works so I can change it how I want.
    Love the accent, 'Good' !

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

    I love it, really good from the start to the end, thanks you man !

  • @user-sl6yv2uh2v
    @user-sl6yv2uh2v 6 місяців тому +1

    Amazing tutorial. I love you

  • @t0xangames207
    @t0xangames207 7 місяців тому +1

    Thank you very much for this tutorial! Everything is very clear and without confusion

    • @GregDevStuff
      @GregDevStuff  7 місяців тому

      Check my Discord channel in help pinned message on how to expand and improve the system to work with scalable UI

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

    Amazing video. This tutorial is very helpful. Thank for your work :3. Respect from Vietnam

  • @bluei4965
    @bluei4965 3 місяці тому +1

    Very good video! Thank you a lot for your work and explanation :)
    If you want the itemToInsert to check if it can fit rotated, you can just copy this under the CheckAvailableSpace:
    if(CheckAvailableSpace(x,y,itemToInsert.Height,itemToInsert.Width)){

    itemToInsert.Rotate();
    return new Vector2Int(x,y);
    }
    It will cost more performance but depending on the inventory size you are going for it should do the trick. ^^

  • @adamen111
    @adamen111 Рік тому +8

    If you can't place item after creating it with Q make sure you disable raycast target on the item prefab Image component

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

    Liked, Subscribed, and Belled for good measure. Excellent tutorial.

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

    Super nice tutorial, thanks for the explanations!

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

      Thank you for watching! Check my other series i have a lot of stuff!

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

    Right from the start perfect tutorial. Thanks

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

      Join discord, there is a fix for resolution problem, in pinned messages.

  • @hofficial1992
    @hofficial1992 Місяць тому +1

    Superbly explained

    • @GregDevStuff
      @GregDevStuff  Місяць тому +1

      Check discord there is some expansions and optimization to the grid system!

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

    Huge thanks, I learned a lot

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

    Awesome tutorial, if you are in doubt and have been searching for a good inventory tutorial for a while, look no further.

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

    Very useful tutorial, thank you so much!

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

      Glad it was helpful!

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

      ​@@GregDevStuff How about Grid Inventory part TWO ? Ideas:
      * Drop items to the floor.
      * Items in steck.
      * Window with a description.
      * Item interaction (e.g. load weapons, unload weapons by dragging ammo in the inventory)
      * Button 'Grab all' from chest.
      * Different inventory for different characters
      * Accounting for the weight of items.
      Thanks!

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

    thank you fork your kindness. I really like this video.

  • @seroffsergey2315
    @seroffsergey2315 Рік тому +2

    Good job bro! This is definitely a like.
    From myself I added to the Rotate method: if(itemData.width == itemData.height) { return; } So that an object with the same size does not rotate :)

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

    Очень классная реализации, я когда то делал инвентаря на IMGUI (без вращения), поймал такие флешбеки))
    Нашел єто видио, захотелось уже на юнити UI сделать)
    поворота предмета - так не хватает многим grid base инвентарям, во общим заразили вы меня идеей повторного написания)) Однозначно лайк!

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

      Без проблем!)

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

      Do it, I am. You can't let the Americans beat you!

  • @JosuEnbeita-ol7kq
    @JosuEnbeita-ol7kq Рік тому +1

    Nice job bro!

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

    best tutorial ever

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

    Awesome video bro!

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

    Feels so hard to convert it into the new input system - thanks a ton for making this video though. This is great!

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

      any luck? I'm having issues with the OnPointerEnter events not firing, unsure if IPointerEventHandler doesn't work with the new system or if something else is interfering.

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

    Красавчик, брат, спасибо =)

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

    Very good!

  • @sayandas-jd7yp
    @sayandas-jd7yp 5 місяців тому

    tnx you save my life

  • @Raul-ef6ct
    @Raul-ef6ct 7 місяців тому

    Thank you, bro

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

    Gosh this video helped me out a tonne, I was trying so many other methods to make this work. how you would recommend about creating a save and load function and nesting inventories. Honestly your work needs to be appreciated more.

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

      JSON or XML for the save load.
      Nesting inventories should work out of box, you simply have to enable/disable them when needed.
      You can help by spreading the word about the channel around social media and the friends. Thank you for kind words.

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

    guess whos getting a shoutout on the credits of my game! its you!!!

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

      THANKYOU! :) Good with the game. Remember to join discord we have showcase channel.

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

    lifesaver

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

    This was excellent tutorial as someone who was new to unity it went a bit fast at times but I assume this is angled towards more experienced peoples. Would you follow up by going from inventory to the ground and back?

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

    Would it be possible to save the Inventory (the class that stores the references for the InventoryItems) as a Scriptable Object aswell to have it available in multiple scenes?

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

    Hi there! Awesome tutorial, very informative! I do have a few question however: What would be the best way to make a "loot chest" with your system? As in having a randomly generated grid with item in it that changes everytime the project is ran. Also is there a way for you to move the grid around during runtime? Currently if I try to move the grid during runtime all the items no longer works.

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

      1st you need to create an actual data structure for items. Right now at best this is just an framework/visual representation. Which bares no actual functionality on its own.
      To deal with chests, it should be easy to simply use 1 grid which you resize when needed(be calling Init with the size of the container). If push to optimization come, you can pregenerate array of bigger size, and limit it based on opened chest.
      I think it should be working fine if you move it aorund at run time, but even if it was working, i don't think it is a good idea to have a bunch of grids you move around for wtv reason.
      Remember you can predict everything what will be happening in your game. It is obvious that for example there will be player grid + chest grid. Just create them and place them into the point of origin at the start. If you are having more slots like pockets and stuff. Make them in advance. At the end of the day, the hit to performance because you have like 3-4 screens done in advanced with all grids created in advance, will outweight the hit to performance if you are constantly instantiating stuff around.
      If you really need to move the grid around, look into the on grid position calculation, i think something is breaking down because of how i made this grid, when you move it around.

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

      @@GregDevStuff Awesome thanks for the quick reply!

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

    hello love your video but i am having trouble when pressing w if i add to many objects it goes in the corner like what heppened when you pressed q, is there anyway to find out why it does not calculate when the grid is full for me?

  • @libiroli
    @libiroli 4 місяці тому +1

    Thanks for this tutorial. Any thoughts on using this approach vs building a similar system around IDragHandler/IDropHandler?

    • @GregDevStuff
      @GregDevStuff  4 місяці тому

      Not 100% sure, but i think yes it is possible to use DnD approach yeah.

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

    This... Accent... where r u from?
    nice tutorial btw, great job

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

    man I gotta say you have done wonders with this tutorial, would it be possible to release a tutorial extending this one?
    I was wondering how it would be possible to make a flexible inventory based on equipment pickups. So say I pickup a green shirt it's inventory would differ from red shirt?
    ie. green shirt has 12 slots but red has 8 slots
    also if something is not equipped then the inventory disappears and items ( if any were in it ) are dropped?
    kinda what survival games do?

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

    Hey Greg. I've tried this twice, and I'm copying everything you do, but the coded grid doesn't match up to the one on the screen at all. I can't get the test item to sit in the right square. The coded grid is just smaller than the one on screen. Also, you don't need to find components like that all the time. You just need to reveal the field in editor and drag and drop. Including the rect!

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

    How could I make this scale properly with screen sizes? Do I just double the grid and sprite sizes when it goes past a certain resolution?

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

      On my discord server there is an explanation how you can make it scalable.

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

    Hi Greg, awesome tutorial, plenty of great code practices as well for a fairly new coder such as myself.
    I have one question, i'm interested in making a non-square or rectangle shaped item.
    how would i go about making a 3 slot L-shape item? Is it possible to join two rect transforms together to form this? Or am i thinking about this all wrong? Any insight would be helpful!
    thanks and keep up the great content!

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

      Yes absolutely possible. And possible to make in this type of the inventory. You should keep ONE texture/object per one Item. But on the Data layer, you know your nodes in the inventory, you should assign the actual shape of the item.
      Honestly i did inventory like you mentioning, and i'll say, it is not worth the effort. IMO. But maybe your game really requires it in that case good luck.

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

      @@GregDevStuff thanks for the quick reply, i'll try messing with that after work! 90% would just be rectangular like your tutorial, but I am messing with an idea of a charm inventory with a few more unique charm combinations.
      The only other thing i need to figure out is incrementally increasing the inventory size by one slot at a time. For example if i have a 6x3 inventory and expand one slot into 7x3.
      There must be a way to add another row to the array but not let the other two slots of the row be selectable yet.
      Another idea would be to just have a max size, eg (10x4) and only show what is unlocked or usable. Anyways i'll play with these ideas more and come crying to you for help later :)
      Thanks for the fast reply by the way mate,
      love from Australia!

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

      @@TheFlintMontana It should be possible to resize the inventory with some fenangling with code.

  • @Toki-
    @Toki- Рік тому +1

    Бля, ребят, отстаньте вы от его акцента, как по мне британский, что очень схож с русским, является одним из понятнейших. Да и согласитесь, лучше если человек проговаривать каждое слово, как минимум в гайдах, нежеле чем произносит с "правильным" акцентом(хз кстати, что вы считаете за "правильный", наверно американский?) и при этом смазывая каждую букву😅
    Спасибо Грег, очень помог гайд)

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

      Забей, там очевидно тролль и я чото забейтился. Мой косяк. Но всеравно мне реально не понятно одно, почему вот горит только у русско говорящих на тему акцента или как тот субъекты говорил произношение.

    • @Toki-
      @Toki- Рік тому +1

      @@GregDevStuff Скорее всего фича в школах такая, у меня был учитель, который люто дрочил за произношение. Как говорится:"Всё из детства") А гайд действительно годный👍

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

    Hi there, ended implementing the grid in my project and found easier to have another image on the item prefab for highlight and use ipointerenter and exit methods to enable and disable, even changing color if can or can’t place the object. Just in case anyone prefers that.

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

      That sure is easier, yet you double your object count for convinience. Which is going to affect performance on a large scale inventory.

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

      @@GregDevStuff Good point.. mmm not an easy way eh?

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

      Found another advantage of the second Image in the itemprefab. This way you don't need to carefuly size your objects. I went almost crazy calculating sizes in pixels to keep proportions and so on.... CRAZY!! I need to choose between performance or insanity! :)

  • @benboj5008
    @benboj5008 10 місяців тому +2

    The GridInteract script doesn't appear to work for me as the selectedItemGrid isnt assigned when I move my mouse over the grid. Also when using the debug to check when it enters and exits the grid nothing happens. I added a check to see if the inventoryController was null but it isn't so that's being assigned correctly. When using the debug in the InventoryController script to check what tile in the grid the mouse is on that also works perfectly fine. I've gone back and compared all the code I currently have and its exactly the same as shown in the video and I also made sure that the scripts are on the correct object and they are so I'm really not sure what's gone wrong and why it wont work. I do have another canvas in the scene but it is currently disabled, just in case I did try moving the canvas both above and below the other one in the hierarchy but that didn't appear to make a difference.

  • @user-ij9ed2bc4i
    @user-ij9ed2bc4i 8 місяців тому

    ok so basically this approach needs like 3 or four major adjustments. the most important one: setting collected items as children of the grid will bug the onpoinexit event

  • @dsdmrr
    @dsdmrr 10 місяців тому +1

    if you add text-like elements to the item, don't forget to turn off raycast target!

    • @GregDevStuff
      @GregDevStuff  10 місяців тому

      Yes. Or the element will obscure the mouse input.

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

    When live reloading i get NullReferenceException: Object reference not set to an instance of an object
    InventoryController.LeftMouseButtonPress, but otherwise it works fine. Its just when it looses reference after a reload, but im not sure why or how to reinstansiate it into a working state

  • @Koko-gn4jb
    @Koko-gn4jb Рік тому +1

    in object highlighting the highlighter is always above the object, not on top of the object pls help

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

    Hi Greg Dev Stuff, i've followed along with your video exactly as your typed it yet my items can't be picked up or dragged / move at all what have i done wrong. thanks in advance

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

      Hard to say without seeing your code, join the discord, and i can look into it on the discord.

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

    How to remove item when we take it out of the grid? Please, brother *.*

  • @matilha4193
    @matilha4193 6 місяців тому

    Hi! I hope you can help me !!
    I create the grid, and I debug to see the grid location for example 0,0 and when I get to the middle of the tile, it's already 0,1 or 1,0 !!!

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

    Hey, Great tutorial! I would like to know how to add an item when the grid is hidden and it is not touching the mouse. I managed to add item but the problem is that you have to keep the mouse on the ItemGrid for the item to be added. Could there be a solution to fix it?

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

      I think I found it. I put in the awake of GridInteract : inventoryController.SelectedItemGrid = itemGrid;
      and I deleted OnPointerEnter and OnPointerExit.
      What do you think about it ?

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

      @@ZeyFightyou will have to think differentely for this. You have data storage for the items, and you want to simply add items directely to this items storage instead of using the grid we are interacting at the moment. You can join discord and we can discuss it further there.

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

    man! you are legend! Thank you so much! What about resident evil 1998 item menu?

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

      Its really not that different from most of the slot based inventory systems. But i'll add it into list of suggestions thank you very much for the input.

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

      @@GregDevStuff If I pay you will you do it? just same system as resident evil 3 2001? ua-cam.com/video/1r0TSwsAHLs/v-deo.html

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

    Hi, fantastic tut. But I have an issue with the multiple inventories. When I drag an item from one Inventory to an other the draged item takes over the OnPointer... event and it does not react on inventories that are "behind it" in the scene chierarchy. Any ideas how to solve this? (when temporarly while draging I place the item in container behind the inventories it works like a charm but... items are then covered)

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

      SOLVED: Item Prefab had Raycast target turned off like so 19:33 but its nested elements had Raycast target still checked.

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

      @@papatomicjusz Yep :)

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

      @@papatomicjusz Thanks my guy!

  • @777redhood
    @777redhood 2 роки тому +2

    Can you please make a tutorial on how to combine amd examine items like in resident evil village

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

    It seems though that when trying to keep the UI scale with the screen size, it starts to mess up. Any ideas on how to fix this? would i have to change the cell size relative to the screen size?

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

      Just want to say very awesome tutorial though, honestly didn't have any other problems. Straightforward and very understandable !!!

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

      To solve this problem use the canvas scale factor (yourMainCanvas.scaleFactor) and multiply it by the width and height of the grid before dividing it by the mouse position relative to the corner of the grid container

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

      By default the value of the scale factor is 1 but actually there is another script that passes the scale factor of the Canvas, It looks like this: _Grid.WorldToGridRelative(GridContainerCorner, mousePos, MainCanvas.scaleFactor);
      public Vector2 WorldToGridPointRelative(Vector2 origin, Vector2 point, float ScaleFactor = 1)
      {
      var gridRelativePoint = new Vector3(point.x - origin.x, -(origin.y - point.y));
      gridRelativePoint.x = Mathf.Floor(gridRelativePoint.x / (Width * ScaleFactor));
      gridRelativePoint.y = Mathf.Floor(gridRelativePoint.y / (Height * ScaleFactor));
      return gridRelativePoint;
      }

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

      I hope it will help you!

  • @duriniskawaiiiiiiiiiiiiiii7593

    at 1:26:22 you guys should add
    if(selectedItemGrid != null)
    if you guys dont add this it will debug error log when alt tab or change tab

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

      How exactly? Having a return or just another nested if? If you could provide an example i'd be happy :)

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

      @@Nomaddev lmao i couldn't fix it
      it not work

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

      @@duriniskawaiiiiiiiiiiiiiii7593 nooooo :(

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

    Hello everyone. Any ideas how I could implement an infinite grid inventory? Cause as of now the grid displayed is the full space. Is there a way to add like a scroll bar and have even more space below??

    • @Notllamalord
      @Notllamalord 9 місяців тому

      a little late but just make it as long as you want, put on a mask and boom

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

    you mention elsewhere that you think theres systems here that could be done way better, whats an example of one?
    great tutorial btw, this is extremely helpful

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

      Instead of using actual position on the screen, use relative position on the screen. Extract input into seperate component.

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

    Hello ! Any clue to handle the canvas scale? If the canvas scaler is set to something different of constant pixel size, then the positions will be offseted because of the scale. Now 32 pixels are no more 32 pixels...

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

      Use the "Constant Pixel Size" on the Canvas Scaler, and set the Scale Factor to 1, and Reference Pixels Per Unit to 100, that way, they are always 32 pixels (or whatever the value you choose) :D!

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

      @@tiagoalmeida2194 This is the biggest problem. Unity's tools for controlling the UI are terrible. countess ways to do it wrong, and maybe one way that will work. What about what render mode to use on the canvas? Or the camera set up.
      What finally worked for me was Camera normal perspective. Canvas Screen Space - Overlay

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

    Great tutorial! By the way, how could I make it work with non-square items like Tetris bricks( L's and Z's ) ? Thanks !!!

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

      In the item data, you need to introduce shape, and when you are placing item use this shape somehow.

  • @st5531
    @st5531 9 місяців тому +1

    Привет, на 4:19 ты растягивал мышкой, но так же мог прямо в инспекторе ввести в поле сразу на сколько клеток строишь (64 размер клетки) 64*20 (20 клеток к примеру) инспектор сам просчитает и вставит ответ 🤔
    Хороший видос, спасибо 🤗

    • @GregDevStuff
      @GregDevStuff  9 місяців тому

      Да кстате, я вечно забываю что мат выч можно вводить там.

    • @st5531
      @st5531 9 місяців тому +1

      @@GregDevStuff Немного комментов еще прочитал, спрашивали на русском видос, непонятные люди кнч, у тебя код перед лицом, даже если ты не понимаешь английский то код то должен разобрать 🙂
      Хотя может это дети смотрят которые и то и то не понимают 😮‍💨

  • @anonymoususer6664
    @anonymoususer6664 Рік тому +3

    Not sure if someone found a solution for this yet, but I was able to fix (at least for me) the "index was outside the bounds of array" error that's occurring for the following line in "InventoryController": "itemToHighlight = selectedItemGrid.GetItem(positionOnGrid.x, positionOnGrid.y);".
    Within the "GetTileGridPosition" method in the "ItemGrid" class, I subtracted a small float value (- 0.001f) to give basically a pixel sized buffer when going out of bounds to the right or bottom (never got the error when exiting the grid from the left or top).
    My code looks like this for lines 35 and 36 in the GetTileGridPosition method within ItemGrid class:
    positionOnTheGrid.x = mousePosition.x - rectTransform.position.x - 0.001f;
    positionOnTheGrid.y = rectTransform.position.y - mousePosition.y - 0.001f;
    It previously looked like this:
    positionOnTheGrid.x = mousePosition.x - rectTransform.position.x;
    positionOnTheGrid.y = rectTransform.position.y - mousePosition.y;
    The errors *should* stop occurring if you're getting this error - haven't gotten the error since implementing that part to my code and there doesn't look to be unintended side-effects. So, that looks to have fixed the issue in my case.

  • @user-jz6bc3lp5r
    @user-jz6bc3lp5r Рік тому

    Very good tutorial, but I can't understand why the items when the inventory is full, go beyond the border to the lower left of the screen

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

    Hello man, I found your video so helpful But I wanted to know what changes should I do to instead of using a lot of small tiles, use a png with the tiles in the same photo. For example, I have the inventory image with a size of 3x4. Am I making myself understood?

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

      No i'm sorry, i'm not sure i uderstand the question. Do you mean you don't want to have square tiles? Like having 120pixels / 80 pixels size "slots"?

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

      @@GregDevStuff Sorry if i was not clear. What a meant was like, you use an inventory png already prepared and sized, with all tiles placed, and all tiles belong to that png.
      Imagine every "*" is a tile.
      You use a png like this;
      *****
      *****
      *****

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

      btw, your video it is being really helpful, as I'm starting with unity and I'm learning a lot about what you can actually do in code part.

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

      @@unlocoahiniideamiapellido9982 Okay i get it, i think you can match the size of each tile on this png sprite and it should work fine. Should.

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

      @@GregDevStuff Yeah, Indeed it works! Thanks, I really appreciate it. Keep it up with such a good content

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

    Thanks for tutorial. I have an issue. When i drag an item from one grid to another, item icon “hides” under grid and i see only highlighting, but no icon of drag-able item. Help please!

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

      The zdepth of the UI is dependent on the position of the object in the hierarchy on the scene..

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

      Hey, did you ever find the solution? No matter what sorting layer or however I order it in the hierarchy the item always go below.

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

      @@bebros2 SetAsFirstSibling for grid (inventory) when OnMouseHover helped. UA-cam delete my comment with code lol.

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

      @@jarekshark1356 That worked. Thanks :)

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

      @@jarekshark1356 Can you tell me where to insert this code? In the OnPointerEnter?

  • @miquelnavalles6679
    @miquelnavalles6679 11 днів тому +1

    I'm sorry, I may have missed the part where you explain it but, how do you do it for the items always appears on top even with multiple grids? Also, when there is no space in the grid, it just places the item outside of it. Is there any solution I didn't see?

    • @GregDevStuff
      @GregDevStuff  11 днів тому

      Its a little weak point, but at the end, ensuring items are on top through hierarchy manipulation. But today i would use more like layers systems.

    • @miquelnavalles6679
      @miquelnavalles6679 11 днів тому

      @@GregDevStuff I already did the last Sibling thing, but because it dosen't changes grid when you move it around but instead it does when you click, the object stays in the inferior grid and dosen't go to the front

    • @GregDevStuff
      @GregDevStuff  11 днів тому

      @@miquelnavalles6679 I would store all items on a higher layer than grids. This is the easiest solution to the problem. Sorry i improved over the time in skill. If you need more detailed explanation jump into the discord i can help you there.

    • @miquelnavalles6679
      @miquelnavalles6679 10 днів тому

      @@GregDevStuff Thanks, I'll be staying in the Discord, but it appears that I already solve it. I used rectTransform to put the object to root. Thanks a lot for even responding to a video that's 2 years old. It was a masterpiece and I hope another of your videos could help me in the future.
      Here's the code I used:
      private void PickUpItem(Vector2Int tileGridPosition) {
      selectedItem = selectedItemGrid.PickUpItem(tileGridPosition.x, tileGridPosition.y);
      if(selectedItem != null){
      rectTransform = selectedItem.GetComponent();
      rectTransform.SetParent(rectTransform.root);
      rectTransform.SetAsLastSibling();
      }
      }

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

    Hey Greg, loved the tutorial it worked perfectly for me except for when I try to make the UI scale with screen size, if anyone has any suggestions I would love the help.

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

      Hey on my discord there is a fellow who expanded upon the system. You can join and in the help channel check the pinned comments, he expands upon many features of this tutorials and i think that includes your issue.

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

      @@GregDevStuff thanks so much

  • @PsicologiaReact
    @PsicologiaReact 3 місяці тому

    when instantiate the item it doesnt fit at the center of my grid slot
    :c

  • @phonglam1134
    @phonglam1134 8 місяців тому

    how check if all tile full cant spawn??

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

    Anyone have a fix for when you move an item from one inventory to another and it ends up behind the image of the other inventory till you place it?

    • @GregDevStuff
      @GregDevStuff  Рік тому +2

      Make a container for carried object. Ensure that this container is on top of everything on the canvas, parent the object you carrying to that container.

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

      @@GregDevStuff Thank you so much you legend

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

    Hey man, amazing tutorial!
    I have only one, but probably big question. Everything works absolutely correct with "Constant pixel size" in Canvas UI scale mode. But how to make it work with "Scale with screen size"?
    Заранее спасибо!

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

      That is a common question, which probably i should adress at some point, but in that case you probably will need to calculate relative position(normalized 0..1) on the canvas, and convert it to the position on the grid.

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

      @@GregDevStuff Ладно, попробую покопаться с этим. Еще раз спасибо!

    • @devilbob
      @devilbob 2 роки тому +12

      Finally found a solution!
      Firstly we need to change localScale of an item we trying to insert, so it will fit for our canvas.
      Add *itemToInsert.transform.localScale = canvasTransform.localScale;* as the very first line in the InsertItem method in InventoryController;
      Then we need to properly convert our mousePosition to current scale.
      Just pass *canvasTransform.localScale* as a second parameter to GetTileGridPosition method as Vector2. Then divide by it while calculating tileGridPosition just like so:
      *tileGridPosition.x = (int)(positionOnTheGrid.x / tileSizeWidth / screenProportion.x);*
      *tileGridPosition.y = (int)(positionOnTheGrid.y / tileSizeHeight / screenProportion.y);*
      And you good to go!
      Hope it will help if someone is struggling with the same problem!

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

      One note:
      I'm receiving new Items from the outside, so this code works for me. If you are receiving items from InsertRandomItem() then you need to change *itemToInsert.transform.localScale = canvasTransform.localScale* to *itemToInsert.transform.localScale = **Vector2.one*

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

      @@devilbob Hey Devil Bob! are you on Greg's discord? i tried to implement your code today and i couldn't get it to work. Id really appreciate some advice.

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

    Hi Greg, Massive thank you for this tutorial. It helped me wrap my head around the concepts of a tetris style inventory. To help myself understand what was happening I have extended the inventory to better suit my game’s needs. If anyone is curious what you can do to extend this system here is a link ua-cam.com/video/mYZnhT6tbRc/v-deo.html. Thanks again. take care!

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

    Great tutorial, but I have a question: I am using it in 2D, and when I change the size of my Game view, the grid moves with it (in and out of the screen). One solution I found for this is to change the canvas scaler ui scale mode from constant pixel size to scale with screen size, but then the entire inventory does not work because the items spawn smaller and placement is weird. Does anyone have a solution for this?

    • @GregDevStuff
      @GregDevStuff  11 місяців тому +1

      Yes on my discord help channel there is solution for scalable inventory.

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

      @@GregDevStuff Ty ill join now 🙏

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

    How much code i have to rewrite to make this work with canvas set to Scree Space - Camera? I really need to change the icons to a 3d object

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

      The idea should be the same, only problem is controls, you can join my discord i have pinned comment explaining how to use this system with more modular control set up.

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

      @@GregDevStuff Joined, but i cant find this lesson :(

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

      @@alphaw1gaming85 Check the pinned comments in #help chat

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

      @@GregDevStuff Pinned by Daniel Rey? IT WORKSSSSSS OMG.

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

      At least the part of pick, move and place the item in the inventory. Now i've to fix the highlight that gets messy, but werever :D

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

    I need help. I get this IndexOutRangeException error on this line .
    public InventoryItem GetItem(int x, int y)
    {
    return inventoryItemSlot[x, y];
    }
    this part calls the function, if it is not there and I click close enough to the grid it throws an error
    itemToHighlight = selectedItemGrid.GetItem(positionOnGrid.x, positionOnGrid.y);
    my Init is this:
    private void Init(int width, int height)
    {
    inventoryItemSlot = new InventoryItem[width, height];
    Vector2 size = new Vector2(width * tileSizeWidth, height * tileSizeHeight);
    rectTransform.sizeDelta = size;
    }

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

      It gets thrown for every tile space your mouse moves through that is not on an inventory grid until your mouse first enters the inventory grid. I am hitting this issue too and am not seeming to be able to find a way for it to not run that line until the first time the mouse enters an inventory grid.
      Cause for some reason it seems to run itemToHighlight = selectedItemGrid.GetItem(positionOnGrid.x, positionOnGrid.y);
      even while within an
      if (selectedItemGrid != null)
      {}
      statement contains it

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

      @@shadedergu9921 Hey did you ever figure this out?

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

      Hey, did you ever figure this out?

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

      @@TheRoarer sadly no
      I tried everything I could but it never worked

  • @user-pm2fj8ol1q
    @user-pm2fj8ol1q 7 місяців тому

    i have no idea what happened. i did the entire tutorial. everything worked and right after i completed the "Rotate Items" section, i pressed "Q" to generate an item and test it out and it crashed unity. reloaded. tried again. crashed again. Tried to undo the code from that section and now i cant place items, nothing is highlighted, a bunch of errors. Any ideas on how to fix it? I put like 10+ hours into this and now nothing works

    • @GregDevStuff
      @GregDevStuff  7 місяців тому

      Discord please.

    • @bryan4884
      @bryan4884 7 місяців тому

      @@GregDevStuffblevin93

    • @GregDevStuff
      @GregDevStuff  7 місяців тому

      Join my server please.@@bryan4884

  • @KannieGamen
    @KannieGamen Рік тому +2

    could i try this with a 2d pixel game?

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

      Absolutely, with no changes to code whatsoever.

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

      @@GregDevStuff Thank you so much!

  • @Nomaddev
    @Nomaddev Рік тому +9

    To anyone else having the error "index outside of range" around 1:25:00 here's a fix that worked for me. This error happens because (at least for me) when you enable the canvas again the mouse will spawn in the middle of the screen which is outside the range of the actual inventory.
    In GetTileGridPosition add:
    if (tileGridPos.x < 0)
    tileGridPos.x = 0;
    if (tileGridPos.y < 0)
    tileGridPos.y = 0;

    • @k.j.305
      @k.j.305 Рік тому

      God this was stressing me out. I hope this works. Will try it out!

    • @Notllamalord
      @Notllamalord 9 місяців тому

      Had the same error around 1:33:00 and it's because GetItem() does not check if the x/y is inside the array, you have to add a check for that

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

    I put if(HEIGHT != WIDTH) check in the Rotate method at the end of InventoryItem.cs so only objects it make sense to rotate will.
    Also, I put rectTransform.SetParent(canvasTransform); right above the rectTransform.SetAsLastSibling(); in the PlaceItem method in InventoryController.cs, as well as adding both of those lines to the PickUpItem method just below. This makes sure the items selected stay on top always and on top of other grids.
    The next step is to figure out how to save this data to a save game file, like json so the inventory persists after turning off the game.

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

      Thanks, was having the same issue.

    • @Notllamalord
      @Notllamalord 9 місяців тому

      this is just a visual, you need an actual data structure

    • @Khyrid
      @Khyrid 9 місяців тому

      @@Notllamalord True but don't bother with Unity start over in Godot or Unreal engine lol.

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

    Включил видюху, и не пойму, вроде русский говорит, а вроде слова забугорные))) Эффекту ошпаренного языка нет) Или как говорят горячая картошка во рту. Ну в любом случае молодец.

  • @WillowBeans123
    @WillowBeans123 6 місяців тому

    Great tutorial but I can figure out something, the rest all works but when I make a item that’s 2 high it will require me to place it at the very top of the grid space for it to place where I want it instead of where it is, if anyone can help me that would be great

    • @GregDevStuff
      @GregDevStuff  6 місяців тому

      is it not being placed automarically?

    • @WillowBeans123
      @WillowBeans123 5 місяців тому

      No when I place down an object it will go downwards for how long it is

    • @WillowBeans123
      @WillowBeans123 5 місяців тому

      If that makes sense, like one tile down per how many tiles tall it id

    • @GregDevStuff
      @GregDevStuff  5 місяців тому

      @@WillowBeans123 Most likely there is something off with calculation of position. But, if you have an issue we better to discuss it over discord, will be easier to figure it out.

    • @WillowBeans123
      @WillowBeans123 5 місяців тому

      Ok thanks I’ll look into it

  • @red.shadow833
    @red.shadow833 5 місяців тому +1

    33:42