Equipping Items - Items & Inventory in Unity (pt.2)
HTML-код
- Опубликовано: 7 янв 2025
- Part 2 deals with input detection (clicking item slots), equipping and unequipping items.
We continue with our implementation of an inventory system and items in Unity, trying to maintain a clean code architecture, with minimal dependencies between classes. The SOLID set of principles is a good thing to keep in mind.
► Next Video (Part 3): • Stats Panel & Characte...
◄ Previous Video (Part 1): • Items & Inventory in U...
► Items & Inventory Playlist: • Items & Inventory
► Character Stats Playlist: • Character Stats
💾 Source Code: bitbucket.org/...
💬 Discord Server: / discord
Resources:
✔ Download UI: www.mediafire.c...
✔ Download Icons: opengameart.or...
In this tutorial series we learn how to implement an inventory system and items in Unity, typical of an RPG: With items, tooltips, equipping items by right click or drag and drop and applying stats to your character.
We'll try to maintain a clean code architecture, with minimal dependencies between classes. The SOLID set of principles is a good thing to keep in mind.
Items are made using ScriptableObjects. Classes are linked together using C# events. And we'll learn the intricacies of Unity's UI components such as Layout Group, Layout Element, Content Size Fitter, Text, Image, and more.
● SOLID principles: en.wikipedia.o...
● SOLID Unity keynote: • Unite Austin 2017 - S....
● Introduction to Scriptable Objects: unity3d.com/le...
Music by TeknoAXE
Retro Future Nights - • Retro Future Nights - ...
Small Whale - • Small Whale - Funk/Ska...
Burnt to a Crisp - • Burnt to a Crisp or Bl...
UNEQUIP SOLUTION: This worked for me and I've scrolled through all the comments for literal months in vain. If you can't unequip items from your equipment panel - or you can't equip them from your inventory - or you are in any situation where your clicks seem to not be working, try making sure any overlapping elements that aren't checking for clicks have "Raycast Target" turned off. Overlapping Raycast Targets tend to screw with each other. This option is in the object's "Image" component. For me, disabling "Raycast Target" for both the Character Panel and the Equipment Panel - both of which were overlapping my equipment slots - finally solved this issue. I truly hope this works for anyone out there who is still watching this. If not, please don't give up! Just keep searching and experimenting and you'll eventually figure it out like I did.
If onRightClickEvent keeps reading null, try Kryazrel's advice. Copying from Kryazrel: "This is one of the caveats of using OnValidate(), that I totally missed, I'll probably talk about this (and the suggested fixes) in a future video. The problem here is that we're only assigning items to slots (by calling the RefreshUI method) in the OnValidate() method of the Inventory class. But that only runs in the editor. So in a build, we never RefreshUI(), which makes the slots think that they have no items, even though their sprites are fine (but those are serialized so they persist from editor to builds).
There's two solutions for this:
A) Call RefreshUI() inside the Awake() or Start() methods in the Inventory class.
or
B) Add the [SerializeField] attribute to the "_item" variable in the ItemSlot class. In this case, even though we don't "RefreshUI", the items assigned to each slot will be saved and persist when you make the build.
Try changing the Awake to Start in the Inventory and EquipmentPanel classes.
This solves an issue that I didn't forsee when making the video, where if the Awake in those classes runs before the Awake in the Character class, the events will be null and nothing happens when you click the item slots"
To see how this is fixed go to pt.8, here Kryzarel show some bugs fixes like this. Everything done in pt.8 bug fixes is relavent at this stage so just go do that now!
ruclips.net/video/Tv6oZJUEiaQ/видео.html
I cant believe these videos are free. You write so clean and so nice. I cant thank you enough. These are just pure gold omg
If anyone is having trouble unequipping items, try moving the code in the EquipmentPanel script's Awake( ) method to its Start( ) method instead.
Thx (:
if adding in "public event Action OnRightClickEvent" around 7:54 isn't working for you, it's because you need to include "using System;"
For those having trouble unequiping items (right clicking it but does nothing) .... try removing the Inventory Manager script and then adding it back (dont forget to add the equipment panel as well as the inventory panel)
thank you so much you just saved me from deleting and rewriting the script, restarted unity and it suddenly stopped working
God bless you!!!!!!!!! It worked for me! I was spending hours thinking about this issue!! ^_^
I did that, but the item is not unequip but adding that in inventory more and more when I clicked
@@gogojames5297 Check the code.
@@parsonbrothersenterprise7677 Dude was really saved my life
This series is so amazing for beginners like me! Coding step by step is the only way for me to learn game system like inventory. Thanks a lot!
I watched two these vids on inventory system, and can say nothing but that the algorithm of your system is hot as hell. Everything just made so good that it's a masterpiece, actually. Thanks for your work. Best videos on inventory system I've ever found.
Wow thank you so much for the kind words
Awesome series man
If anyone is having trouble with a nullreferenceexception error be sure to put an Image Component on you equipment slots :D
I got right to the very end, everything working fine... Except I can't seem to unequip items. I've reviewed my code, and it seems to be in order, so I'm pretty stumped
I'm going to follow your whole series, I just wanted to say thanks! because so far everything has been super clear and easy to understand! Subbed :D
For Those who can't UnEquip item inventory->awake func->Start func and equipment panel->awake func-> start func
Great use of System.Action, inspired me to make some changes in current project!
I have problem if anyone can help me please? Assets\Scripts\Inventory\EquipmentPanel.cs(14,31): error CS1061: 'EquipmentSlot' does not contain a definition for 'OnRightClickEvent' and no accessible extension method 'OnRightClickEvent' accepting a first argument of type 'EquipmentSlot' could be found (are you missing a using directive or an assembly reference?)
Amazing vid realy helped me streamline an inventory system in a text based rpg im working on! Probs to you man!
Thx a lot u're the best i've learn so much from your lessons!
I killed my whole script xD. When i changed inventory manager name. I couldn't find the fault, cause i went into a panic. Now im doing this tuturial while looking at the full finished source. Going over everything that you say. Without actually typeing myself. Makes it faster about 4 times ... i think.
The only code changes i now do, is like add gazillion things in. And make some parts more compact. With some loops. I'm happy how my own UI slowly gets into shape. While useing scroll rect function and stuff. So that i can fit all those secondary and teritary stats in there. Without makeing each and every stat-tree a single UI Panel ... or pop up.
When im done with this tuturial. I will probably integrate this into my prototype game. Just a few changes here and there. Like a Stat application setup, for level ups and co. And i have a simple working Inventory+ stat system. Which should give me some more time to focus on mechanics like battlesystems, skills and auto generateing dungeon floors ... or player editors so they can make floors too.
I hope your well.
Thanks for the very in-deepth explanations!
Codeing = codeing. In the end. But i hate it to slog trough definition texts... and this way i actually see all i need and might not need. That Unity and C# have differntly. Then lets say jacascript, Lua, VBA etc.
You could also add a scriptable object for the Enum ItemTypes to make it even more extensible
My onRightClickEvent keeps reading null so I cannot run through the classes to get to equip and unequip. Can anyone help? Or having the same problem?
Try changing Inventory Awake to Start - there's an explanation from Kryazrel below, basically this is only a partial implementation so the for loop in Awake is not being called to populate the slots with the rightclick handler. Putting it in the Start method ensures the for loop runs and loads the right click event in the slots.
Copying from Kryazrel: "This is one of the caveats of using OnValidate(), that I totally missed, I'll probably talk about this (and the suggested fixes) in a future video. The problem here is that we're only assigning items to slots (by calling the RefreshUI method) in the OnValidate() method of the Inventory class. But that only runs in the editor. So in a build, we never RefreshUI(), which makes the slots think that they have no items, even though their sprites are fine (but those are serialized so they persist from editor to builds).
There's two solutions for this:
A) Call RefreshUI() inside the Awake() or Start() methods in the Inventory class.
or
B) Add the [SerializeField] attribute to the "_item" variable in the ItemSlot class. In this case, even though we don't "RefreshUI", the items assigned to each slot will be saved and persist when you make the build.
Try changing the Awake to Start in the Inventory and EquipmentPanel classes.
This solves an issue that I didn't forsee when making the video, where if the Awake in those classes runs before the Awake in the Character class, the events will be null and nothing happens when you click the item slots"
or those having trouble unequiping items (right clicking it but does nothing) .... try removing the Inventory Manager script and then adding it back (dont forget to add the equipment panel as well as the inventory panel) -
Paulo Calligaris Neto
Not sure if this will ever be read, being an older video but, when I drag the EquipableItem to the Element 0 under Items in the Inventory (Script) after deleteing the first item(non equipable but same item) like you do at 2:40, it places it into the 2nd slot as the 1st slot still contains the original item but the Image (Script) is just unchecked so the Image doesnt show up, the item is still there just not shown so the next item added doesnt go in the 1st 'empty' slot. hope that makes sense. Please help.
Thank you for these tutorials, really well made, keep it up!
Thank you for your comment!
I want to learn Inventory, but seem he's teaching every things! Owesome
These are awesome man. The pacing is perfect for a tutorial. Well done.
Thank you very much! Glad you enjoyed :D
07:00 To detect input from a script, add the UnityEngine.EventSystems namespace IPointerClickHandler
Thank you!
I need help with unequiping armour i can equip it just fine but i cant take it off
or those having trouble unequiping items (right clicking it but does nothing) .... try removing the Inventory Manager script and then adding it back (dont forget to add the equipment panel as well as the inventory panel)
@@xpxneto Thank you! Had the same issue.
@@xpxneto thanks)
@@xpxneto worked for me after I changed scenes the whole inventt system stopped working. Any idea how to make it work while I change scenes and go back etc?
@@xpxneto Thanks mate
Please help! Everything works well but i could not remove equitable item from equip panel. I copy same code from add equitable item to equip panel. And there is no error or whatsoever when i right click to the item in equip panel.
I'll leave this little tidbit here for posterity: If you can't Unequip Items from the Equipment screen, try changing the Awake methods to Start in Equipment Panal and Inventory.
If that still doesn't help, click on the Inventory panal and disable it's image's Raycast Target check box.
If anyone is confused a bit like I have been, the image components of the EquipmentSlots are manually turned off. They do not 'automatically' adjust for their contents precisely the same way a generic inventory ItemSlot does, by virtue of the way their items are assigned. ItemSlots will be updated in the Inventory OnValidate() method, when it loops through and sets all of their items during the call to RefreshUI(). But the EquipmentPanel does not do this the same way the Inventory does, and so the EquipmentSlots will not automatically turn off their image components during OnValidate calls.
I was caught up on this for quite a while, wondering why EquipmentSlots behaved differently than ItemSlots when they inherit from them, override the OnValidate etc.. Then it occured to me, that was only fetching the Image component reference and not turning the it on/off, which is done upon setting the item property. When this is done varies between the two systems (EquipmentPanel vs Inventory).
Hope this helps someone else who gets caught up on this little detail ;)
Thanks so much for this series Kryzarel, such a great reintroduction to solid design principles!
you just need create new Equippable ItemS in Assets/items folder
Yes, this is the same for me. When I hit run, the EquipmentPanel images are white unlike the InventoryPanel images which are transparent. If I right click on Inventory items that are equipable, they populate the EquipmentPanel properly with transparency. When I remove them, the EquipmentPanel is now transparent. How do I get the EquipmentSlot images transparent on startup?
I have a question where exactly in the code is a change from the empty image for example, weapons in the equiple panel needed to me that it is to see what is the picture and set the weapon
most concise information
How could i implement in android platform the ipointerclickhandler?
Well done I learned a few new ways to code thank you +1 new subscriber.
Could you specify for us what the different variables are? I am really having trouble with keeping up with upper case Item, lower case item, Items, another lower case item, _item and so on. Especially the method at 0:25.
public bool AddItem(Item item)
What are those two? The first one refers to the Item class, I'm thinking, but the second one?
Yes, you are correct. The first refers to the Item class and the second is just the name of the variable. Whenever you declare a variable you have to write its type (upper case Item) and you have to choose a name for it, in this case I simple chose lower case item.
In my videos I assume some basic (or intermediate, even) knowledge of programming, so that we can move at a faster pace than most Unity tutorials I see, and hopefully, also create more interesting stuff. That's why I don't really explain a lot of that stuff.
You might want to check out some introductory programming videos. This playlist by Sebastian Lague is quite good: ruclips.net/video/_cCGBMmMOFw/видео.html
Or you can drop by the discord server ( link: discord.gg/98YSpu2 ) and ask literally any programming or Unity question that you want and I'll be happy to help :D
Excellent video, thanks!
Hi, Thanks for this video! I'm having issues after building the project. unfortunately right clicking any item does nothing after the build. i need to re-add the component "Inventory Manager.cs" again just to make it work. Is there something to add in the build settings?? anyway I'm hoping for more videos...
This is one of the caveats of using OnValidate(), that I totally missed, I'll probably talk about this (and the suggested fixes) in a future video. The problem here is that we're only assigning items to slots (by calling the RefreshUI method) in the OnValidate() method of the Inventory class. But that only runs in the editor. So in a build, we never RefreshUI(), which makes the slots think that they have no items, even though their sprites are fine (but those are serialized so they persist from editor to builds).
There's two solutions for this:
A) Call RefreshUI() inside the Awake() or Start() methods in the Inventory class.
or
B) Add the [SerializeField] attribute to the "_item" variable in the ItemSlot class. In this case, even though we don't "RefreshUI", the items assigned to each slot will be saved and persist when you make the build.
Try changing the Awake to Start in the Inventory and EquipmentPanel classes.
This solves an issue that I didn't forsee when making the video, where if the Awake in those classes runs before the Awake in the Character class, the events will be null and nothing happens when you click the item slots.
Great!
@@Kryzarel The awake in the Character class? We don't have a character class yet do we?
@@Kryzarel Thank you Kryzarel the blessed one! Changing from Awake to Start fixed my issue.
I have an issue where I get a NullReferenceException on ItemSlot.sc line 26 "Image.sprite = _item.Icon;" when I rightclick an item in my inventory. The sprites on the Items slots are being populated with the correct sprites and the references to the inventory and the equipment panel are correct. Somehow the sprite from the itemslot is not being passed to the equipment slots. I don't know why.
@kryzarel hey i get the error the modifier public is not valid for this item on the equipment panel public bool removeitem
This was an excellent tutorial (most Unity tutorials suck).
🤘😷👍
Why does when i click a iteam the rightclcik event doesnt happen?
Hey uhm, I don't know if I forgot to do this before, but if someone is stuck on the "clicking not working" problem, add a button to your item slot. You don't need to put a "OnClick" thing, just add a Button to make it work with the "OnPointerClick". It worked for me !
Implementing the IPointerClickHandler interface in the ItemSlot class should be all you need
I know right, but weirdly without the "Button", clicking won't work :/
Weird indeed, there's probably something else going on. Feel free to join the Discord server ( discord.gg/98YSpu2 ) if you want some help to look deeper into it :)
Hi, is there a way to add "base equipment", like armor from the beginning of the game?
It's really Amazing!!!!!!!! Thank you
Okay you answered my question a few times for other people.
Great Videos. Everything works as expected except, when the game first runs, I have white boxes in the Equipment panel where each equipment slot is. They go away after I equip an item to that slot. I watched the videos 2x to see what I may have done wrong but can't seem to find the issue. Any ideas?
He manually disables the image component at 3:32 on the helmet slot, before duplicating out the rest
when i equip an item it works fine but when i unequip it duplicates the item,leaves one in the equipment slot and one in the inventory
Having the same issue been trying to figure it out for three days. Did you ever fix this issue?
@@jodywells4370 you might have missed out the part that replaces the item in the inventory with null value after equip
I little late to ask but, if I got 1 slots of the same tipe (example 2 rings slots) when I equip it, it will equip on both slots, how I prevent that from happening?
nive video btw
Hello, everything works fine until the end. I can't unequp items. Any idea about why this is happening?
I got a problem ;c I can't unequip the items. What can I do? ;c
did you fix the problem?
Why does his code add and remove items, if those functions are inside if?
In the InventoryManager funcion Equip() is missing one RemoveItem after the second if :
public void Equip(EquippableItem item)
{
EquippableItem previousItem;
if(_equippmentPanel.AddItem(item,out previousItem))
{
if(previousItem != null)
{
_inventory.AddItem(previousItem);
}
_inventory.RemoveItem(item);
Hi
Kryzarel, great thanks for your video. I have a question about the equipment. What if I have multiple equip slots such as ring slots? The current method in the for loop can only work for different equipment slots, and it would be great if you can help to make some expansion on this. Thank you!
kinda late but did you get any reply on this? any solutions? am having the same issue with my weapons as i have them cyclable so i got 3 weapon slots all the same
Hi I really like your videos and I will like them all and subscribe if I can get through this lol. One issue is when I right click an item from the inventory, it is added to the equipment panel but it isn't removed from the inventory panel. I can then remove it from the equipment panel by right clicking it there and it creates a duplicate in the inventory, which is somewhat of an issue. This seems like a simple fix but I can't seem to figure out where I went wrong. I would appreciate the help greatly.
Nvm figured it out.
What solved this I had the same issue ?
Excuse me, but how do I save inventory when a character acquires an item?
i dont like the idea of using slots (part of UI) to keep items, why not keep them in array in inventory class instead? So inventoryUI class can be plugged to show different inventories (like if you have different characters under control)?
Brilliant series so far, I am very impressed and am learning a lot! Quick question though, would this work the same when using a controller, or is IPointerClickHandler solely for a mouse? To enable the use of a controller, would you need to add UI buttons for the slots in the interface, or is there a C# magic system I don't know about?
It's for mouse only. You're looking for the Input class in Unity Engine.
I have a bug, I'm not sure if something is wrong with my code, or its a limitation of the current code. But when I try to equip an item identical to the one currently equipped (like two copies of the same item asset) it does not swap, but simply remove the one from the inventory (or perhaps it equips it, but don't return the old to the inventory, it's hard to tell) I would assume that the issue comes with the fact that the sloth reference a scritableobject rather than a gameobject.
Yes, that's a limitation of the "current" code. If you keep following along, in part 12 - Instantiating Scriptable Objects, we fix that limitation :)
It's not about being a reference to scriptable object vs game object, it's just that it's the same reference to the scriptable object in the project folder and not a new instance of it. That's precisely what we fix in part 12.
When I right-click an item, it doesn't go in the equipment panel.
In the OnPointerClick I added
if (OnRightClickEvent == null)
print("onright is null);
and it prints that!
Any idea why OnRightClick would be null?
Resolved this issue by moving the OnItemRightClickedEvent assignments to 'Start' vs 'Awake'
private void Awake() // I changed this to Start
{
for (int i = 0; i < itemSlots.Length; i++)
{
itemSlots[i].OnRightClickEvent += OnItemRightClickedEvent;
}
}
For unequipping items, do the same in the EquipmentPanel script.
after the build, InventoryManager not working wtf?
If anyone has any issues with the clicking not working I had to update the project to include the following link below. Be sure to follow steps 1-8 and I found after also following the steps "By implementing IPointerUpHandler and IPointerDownHandler with empty methods, the OnPointerDown method was invoked as expected." it then worked. Hope it helps!
answers.unity.com/questions/1077069/implementing-ipointerclickhandler-interface-does-n.html
Thank you so much, I'm learning a lot! Hope you are okay!
when i hit play the right click doesn't work to move it to my equipment slots went through the video 3 times
See if you inserted the GameManager script correctly
(explaining better: putting it on the canvas and dragging the inventory and Equipment panel on the variables)
Anyone have any idea on how to update your character to wear the armor he has equipped? I'm using sprites so maybe add a layerweight when a certain weapon is equipped? Or an animation?
Hello,
first thank you for this tuto it's truly helping
i have a little problem with my code, i get this error
Assets\Scripts\InventoryManager1.cs(42,50): error CS1615: Argument 2 may not be passed with the 'out' keyword
Hi there! First of all your tutorials are great!!
I try to follow your tutorials but at the same time i want to change some things and want to modify the inventory to my needs :) but i stuck or i dont know exactly if im on the right track.
The inventory should be like in the shortly released Resident Evil 2 Remake :) I already have that if i hover over the item slots that it wil show the buttons (equip, use, combine, drop). but i dont want to equip on right click, instead i want to equip when i click on the button "equip". but it dont work. i dont use the events like you in the tutorial. i also want to select one slot and deselect if i click on another slot and only show the buttons when the slot is selected. but that also dont work correctly. as for now it only works perfect with the hovering thing ( OnPointerEnter, OnPointerExit). :) Any clues or help for my problem? Thx
I'm creating a game using mainly scripts to manage data and I'm using your tuts to supplement what I'm doing in my game.
Question: I have a class Weapon that extends from an Item class, and from Weapon class, Light, Heavy, Melee, and Mage weapons. I want to be able to "generate" weapons as an enemy drop that have randomized stats, like if I have a Gladius equipped, and the dropped Weapon was also a Gladius, I'd want the new Gladius to be unique. My instinct tells me that I'd need to do something like creating a new variable that hold the new Gladius, then assigning that to a slot in my inventory, but I'm not sure.
Hey man, sorry about the late reply. To create a new unique item, you first need to make a copy of the original item that the new one will be based on. You can do that by doing newItem = Instantiate(originalItem). I talk about that in the latest video, Items & Inventory #12: ruclips.net/video/WXQ_jfvM4CY/видео.html.
After you have the new item, if you want it to be unique you probably want to generate randomized stats for it. You can use Unity's Random.Range(minValue, maxValue) to assign values to each stat between a min and a max amount.
Hope this helps, feel free to ask if you have any other questions!
Thanks for responding! Yes, this helps a lot, I'll also check out the other vid.
I have an issue, everything works fine, I can equip and unequip items. Until I change scene, then when I come back to the scene I can see the items but I no longer can click/interact with them. Even when I restart the whole inventory system stops working. I fixed it by removing scripts and adding them again to objects. But now I still don't know how to make it work with changing scenes.
I have the same problem. Haven't you fixed it yet? If yes, please tell me how
Hi. After save and run Unity again, script's stopped working, when i try unequip item. Any solutions?
Try changing the Awake to Start in the Inventory and EquipmentPanel classes.
This is a fix that I'll have to reference in a future video. The bug happens because the Awake in those classes might run before the Awake in the Character class and the events stay unassigned.
Let me know if you still have issues after that.
Thanks for fast request. Start didn't fix. I used a "Update" in EquipmentPanel and looks that's working.
BTW, great tutorial.
What did you use the Update for, btw? If that fixes you issue I'm glad you got it working, but it shouldn't be required.
And thank you for the kind words :)
Last night it worked and today suddenly wasn't working. I'll try changing awake to start. See if it works for me
Update- Update works. but why is it happening
I'm making an FPS game and I want to make that player can use a weapon only if it's equipped. How can I do this?
Hello! Thank you very much for the tutorial! I had a problem with this line: Assets / GameFolder / Scripts / InventoryCS / EquipmentPanel.cs (12,41): error CS0029: Cannot implicitly convert type `EquipmentSlot 'to` EquipmentSlot []'
Assets / GameFolder / Scripts / InventoryCS / EquipmentPanel.cs (12,41): error CS0029: Cannot implicitly convert type `EquipmentSlot 'to` EquipmentSlot []'
Help please, I can not decide: With
Take a look at your "GetComponent" methods, it's probably supposed to read "GetComponentsInChildren" (plural Components) ^^
Hi Kryzarel. Thanks for your great video. But I have some errors when I equip item from inventory. It call a NullReferenceException: Object reference not set to an instance of an object ItemSlot.set_Item (Item value) (at Assets/Scripts/ItemSlot.cs:23). Someone have any clue?
Hi did you by any chance find a fix for this? I'm having the exact same problem.
@@davidmcpherson6941 I got the same issue... please validate is _item == null with the double == , not just one.
Nice work I have one question how can I use touch mobile imput in the ItemSlot Script?
@Kryzarel help me?
Any idea why my game only replaces items in the equipment panel. I have multiple weapon slots but it only uses one.
For anyone else I solved this issue by adding another if statement before setting the previous item, equiptment slot, and returning true which checks if (EquipmentSlots[i]) is null
@@skollyt6594 can you explain what to do a bit more sir?
Hi man, awesome videos but i have a problem. I am making android mobile game and is there option to some kind interact with this inventory on touch screens?
I'm not planning to revisit this for touch support anytime soon. However, I believe most stuff is already pretty well suited for touch input anyways. The only thing that probably won't work is the "right click" behaviour. You can instead change that to "left click", which gets translated by Unity to a simple tap on touch devices, by just removing the "if" statement that checks specifically for a right button press.
And for the tooltips, you might want to change them to show on a long press, since there is no "pointer enter" and "pointer exit" events on touch. There should be plenty of tutorials around the web on how to implement long press behaviour.
All of these changes should be done at the level of the ItemSlot classes (basically, all the classes that implement the "IPointerHandler" interfaces). That should suffice to have proper touch support. If you run into any unforeseen issues while making these changes, let me know, I might be able to help some more :)
my items arent showing up on game screen but are in scene view
I got some errors when using the equipmentslots array, like error CS0029: Cannot implicitly convert type 'EquipmentSlot' to 'EquipmentSlot[]' Does someone know what's coming on?
What method(s) are you getting the errors? Perhaps you used: GetComponentInChildren() instead of the plural version GetComponentsInChildren()
the singular version will grab the first component it finds of the specified type, where the plural version grabs all components of the specified type.
Hey Man I was wondering if you could add a tutorial to this series about making chests. I’ve tried basically duplicating the equipment panel setup and adapting it e.g. changing variable names, removing equipment type restrictions etc. but I can’t get it to work. I would appreciate it a lot if you could help me out. If you want screenshots of what I’ve done just ask.
Just so you know I have made sure that my “LootSlots” images have ray cast target enabled
Is this in line with what you're thinking about?
ruclips.net/video/x4lnutQI26E/видео.html
Kryzarel thanks for the quick reply, but I was thinking about a conventional chests like you would find in rust or Minecraft. You don’t have to make a full tutorial if you don’t want to make one but if you have any advice that would be welcome
If you want them I can send you screenshots of what I have so far
Right, that would be very similar to the Inventory, except when you right click on items in the chest's UI you need to add those items to the player's inventory. In practice that means you want a class that is almost identical to the Inventory class, but the methods that it calls for its events (OnRightClick, etc), would need to be different. You need to have a reference to the player's inventory (probably easiest to pass it as an argument to an OpenChest method, or something like that) and add the clicked items to it.
I have done everything right but I can't right click on my object and there equippable. I don't need a complicated script just a simple inventory how can I just destroy with a right click instead of wear it. Thanks in advanced
I found out it won't let me click when I have picked items up
I cant Equip any item from my inventory please help me !!
Never mind I'm just using IPointerClickUpHandler instead of IPointerClickHundler
I want to divide equppable items to armour and weapons be seperate.
so i modified the item slot script to work like a classic Resident Evil item slot using a button. However I'm having trouble after this part
if (Item is Equippable)
{
equipBox.SetActive(true);
sound.PlayOneShot((AudioClip)Resources.Load("Decide"));
}
else
{
equipBox.SetActive(false);
}
under the Item is Equippable I tried another if statement underneath it like so
if (Item.ItemName is "SiG Suaer P226")
{
equipBox.SetActive(true);
sound.PlayOneShot((AudioClip)Resources.Load("Decide"));
}
else
{
equipBox.SetActive(false);
}
It compiles without error but now my onClick function doesn't work. Can you give some insight on why its causing me to slam my head on my desk?
nvm i'm an idiot human error my itemname didnt match the string I was trying to get from the Item.ItemName :x
Hey ! So I finished my inventory, and when I built the game and launched it, the inventory doesnt work, like i cant do anything with the mouse ... Though, in Editor mod EVERYTHING WORKS PERFECTLY. anyone has a clue why. ?
Dunno if this is going to help now but click on your player and then click on the script that controls your player e.g first player controller script in the inspector and click the arrow for mouse look, there will be something called lock cursor within it, uncheck that box. You'll be able to see your mouse now.
Hey, I hope you still read the comments under this video, haha. When I click my Item ( the Helmet) it just dissapear and don't go into the helmet slot in the equipment panel. Do you know why that is?
Yep, definitely still reading the comments on every video! :D
There's two steps you have to take when equipping items, you need to remove them from the Inventory and also add them to the Equipment Panel, did you check if both those steps are happening correctly? :)
@@Kryzarel thanks for the quick answer. I checked the code quite some time, even re did it, haha. There seems to be an NullException at "else { image.sprite = _item.Icon" in the ItemSlots script.
@@BlasesInc Did you assign the image component to the Item Slot script in the inspector? I'm guessing it's trying to go image.sprite, but the image is null.
Why my equipment slots doesnt remove to its own panel, And why it is not clickable?
Have you checked if you have the "OnRightClick" events correctly assigned in the Character, Inventory and EquipmentPanel classes?
And if you have the "Raycast Target" option enabled in the image component of your Item Slots game objects?
Hi! I followed your tutorial and also changed the Awake functions to Starts but I cannot unequip my armor once I equipped it.. any idea why this could happen?
Can you describe the steps you took in more detail? Or is it just as simple as equipping works but unequipping doesn't? If so, I can't think of anything of the top of my head. Are the events properly assigned?
It is as you said.Equipping works, unequipping does not.. idk how to show you best.. do you have some social media or mail where I can reach you?
Yes, feel free to join the Discord Server: discord.gg/98YSpu2 and post your issue in the game-dev-help channel. I might not be able to answer in detail right away, but I'll do it as soon as possible, and as best as possible :)
Did you fix this? I've the same problem.
@@TheBrofistStudios did you find it cause im having the same problem
Thank you, Please keep it coming. I already sub your channel for new content.
Thanks for the sub and thank you for watching!
Hi anyone else getting an error "The script "Item"" does not derive from MonoBehaviour, but has been added to Game Object " Item Slot ( _ ) . Please remove the script from the Game Object to avoid crashes." ? This error persists through all item slots except for the first.
Did you by any chance have the Item script derive from MonoBehaviour before changing it to ScriptableObject? And did you add it as a component to the Item Slots before that change?
The only script that should be in the Item Slots game objects should be the ItemSlot script.
Thanks i have no idea why the script was attached to the item slots. Derp :P. Love the vids BTW ! cheers !
Thank you!
Mobile touch?
If anyone was wondering how to use these features on a game object that extends from Inventory.cs and the ItemSlot.cs scripts, I can help. For example I made a HotBar.cs and a HotBarSlot.cs that inherit from these files and got the HotBar to have the same functionality of right clicking to equip.
Dude, I haven't seen your other classes, but did you ever do the keyboard interaction? Still, excellent lessons!
Haven't done any keyboard interaction, no. What kind of interaction would you like to see exactly? :)
We can imagine a console game, there we do not use mouse. So I wanted to replicate this, where using the directionals to walk through the items and options and pressing some key to equip/unquip or to access some other option. Sorry if there is a flaw in my English :D
I see. That makes total sense. We might be able to that easily using Unity's built in navigation. I'll write this down in my "possible future videos" list and I'll look into it.
Thanks for the suggestion! :D
@@Kryzarel I would love to see some keyboard interaction too
unequip doesnt work
will you be adding drag and drop?
Yes I would certainly like to do so eventually, among a bunch of other things like tooltips, stacking and integration with CharacterStats :)
Awesome!! I'll look forward to it.
how to remake it for android?
First of all, I would love to thank you for this; and I will properly credit you in my game's credits.
However, I cannot for the life of me figure out how to get equippable items into an equipment slot? I've followed the video to the T and it ain't working.
Could you provide more detail? Where exactly does it fail? Have you checked if the events are all correctly assigned in the Inventory and InventoryManager classes?
Kryzarel i’ve attached a Debug.Log to the OnPointerClick in ItemSlot. One after InputButton.Right and one after OnRightClickEvent. Neither of those are being displayed, so the script is not even picking up the clicking.
Do you have the "raycast target" option enabled in the Image component of the item slot?
Kryzarel yes, i’ve just even tried using an OnMouseOver function in place of OnPointerClick using the same basic purpose. The result is the same.
Can't really think of any other possible issues of the top of my head. I would suggest you join the discord server and upload your project so that I could take a look myself, if you would like. discord.gg/98YSpu2
Edit: just realized you already joined, derp
I'm trying to link my weapon manager script on my player which controls the equipped image and text(kinda like the old Resident games) to my itemslot script. It works but not as intended, the text in the equipment box decreases but the doesn't update on the item itself inside the slot until i unequip the item and reequip it.
here's the layout of the text control portion on the weapon manager:
ammo.text = m1911.ammoCount.ToString();
and here's the line inside my itemslot:
valueCount.text = manager.m1911.ammoCount.ToString();
ive even added valueCount.text = _item.itemValue.ToString(); and it doesn't update it if you or anyone can help me out I'd be much appreciated.
right clicking doesn't bring the item to the Upper Panel
something i figured for now, the first void awake in Inventory is beign called 20 times without beign pressed
it seems like it doesn't get out (but runs this line) of:
//-ItemSlot-//
public void OnPointerClick(PointerEventData eventData)
{
if (eventData != null && eventData.button == PointerEventData.InputButton.Right)
{
if (Item != null && OnRightClickEvent != null)
OnRightClickEvent(Item);
}
GOD I FORGOT TO INSERT THE INVENTORYMANAGER
all good now but after i equip it it doesn't go back to the inventory
CANT UNEQUIP/EQUIP SOLUTION (possibly)
after a year from this video was posted i have come here to say: if your equip panel and inv panel overlap in the UI in the editor, one of them wont work.
If this isnt the solution you were looking for, i wish you fortunate hunting, son.
(also good tutorials)
why are my images still white on top
Thank you!
INVENTORY MANAGER:
"if (equipmentPanel.AddItem(item, out previousItem))"
previousitem gives error; "Argument 2 may not be passed with the 'out' keyword"
Tried a few different things but so far nothing helped
Check if the method is also declared with the "out" keyword inside the EquipmentPanel class.
Aha! 5:41 I forgot the 'out' on that line, simple fix. Thanks Kryzarel for the quick response and nice tutorial!
Do you have a tutorial or a link for a compatible script I can use to attach the weapons,armor.etc to my characters sprite? I tried doing a script within the body parts themselves and a script attached to other said script, within the items; all it did was erase my characters hand and put the sword way above the players head lol.
Unfortunately I don't know of any tutorials about that. I believe you would have to make your character composed of several pieces that could be easily swapped between each other, or alternatively, create 1 different sprite for each possible situation (that could end up being tooons of sprites, depending on how many possible combinations you have).
Yeah my character is at least 12 separate body part sprites put together, not to mention the different hair I can choose from which is in like 10 pieces each for wind animation purposes. There's gotta be a way to do it, thanks anyway! +1sub