Hey, I wanna apologize for not releasing a video last week, I had been working hard on a video to release alongside the Character Stats asset on the Unity Asset Store, but apparently Unity is taking 20 to 30 days to approve new assets now-a-days (yikes!). Really want both to release at the same time, so I ended up not posting anything :( Hope you enjoy this week's video though :D
Man, thank you so much, I'm really glad you like it! If you have any suggestions or questions that you'd like me to cover in a video, feel free to let me know :)
Finally a tutorial that goes at a fast enough speed, other videos are usually 20-30 mins to not say much. Looking forward to listening to the whole serie!
Hands down the best tutorials on the internet, I've watched probably all others and i can say your way of presenting and actual code architecture are the best! Keep up the good work!
Right now I'm starting this series. Hopefully it'll be good working inventory system for my game. I just wanna to say thank you for your work. You put links to he UI elements and to the source code, it's amazing. You are the best. Cheers!
Hi! hope this video isnt forgotten and my question gets answered: is this tutorial compatible for unity 2019? more specificaly Unity 2019.4.17f1 because i was following the tutorial and everything was fine until 7:25 i got error CS0246. i investigated a little about the problem and seems that it means that "ItemSlots[]" (and every derivate) doesnt exist in case that this code isnt compatible with my current version, is there any way to replace this? What can i do?
For some reason, at the inventory, i wrote GetComponentsInChildren yet it still writes the error CS0246 i shall say that it writes "the type or namespace name 'itemSlots' could not be found Edit:found out
Just stumbled into these videos, Dude your tutorials are amazing! you really know how to elaborate on ideas and information better than most others ive seen. Keep up the awesome content man!
I am getting the following error when I try to save the Inventory Script, so it won't allow me to attach it as a component. Any ideas? Assets\Scripts\Inventory.cs(13,61): error CS0246: The type or namespace name 'Itemslot' could not be found (are you missing a using directive or an assembly reference?) Any idea why I am getting this? My code is identical to this video.
I see loads of tutorials on how to make grid based inventory systems, but none on how to make list based ones like the ones you see in old RPGs such as Final Fantasy, where there were infinite slots for unique items and you could store something like 99 of the same item in one slot. I was wondering, could an inventory like this be adapted into that style of inventory? I'm very new to Unity and C#.
Great work the the tutorials. Most just read the code they are writing without explaining what is going on. Thank you for the detailed explanations it really does help. :)
In the inventory script, I'm getting this error - Cannot implicitly convert type ItemSlot to ItemSlot[] This is on this part of the code I have double checked all the scripts to make sure I dont have any screw ups. private void OnValidate() { if (itemsParent != null) itemSlots = itemsParent.GetComponentInChildren(); // this part im getting the error }
I'm surprised that this worked but now I'm spending forever trying to position my item slots so that's going to be fun. I'm happy that the inventory is fairly modular.
I cant get rid of this error: ''Cannot implicitly convert type ItemSlot[] to UnityEngine.Transform.'' The error is in this line: ''itemsParent = itemsParent.GetComponentsInChildren(); I would greatly appreciate it if someone here would help me.
@@Kryzarel even though I did as shown in the video the whole line after itemSlots = "itemsparents.GetComponentInChildren();" is showing error, & the error code is Inventory.cs(13,37): error CS0029
Really digging the tutorial. Trying to follow along and I get this error on the Inventory script: error CS0246: The type or namespace name 'SerializedField' could not be found (are you missing a using directive or an assembly reference?) Any help would be appreciated.
It won't let me drag my helmet into the items list under the inventory script on my inventory, somebody help I've been stuck for days. I have all the same code, but it still don't work.
I have one issue, when adding my items to the inventory, the itemslots Image component does not enable, but rather stay disabled like its still null. Ive gone over the code for enabling and disabling and its perfect. I dont understand why it does this
in item slots i keep getting this error : NullReferenceExeption : Object reference not set to an instance of an object } else { image.sprite = _item.Icon; // < right here image.enabled = true; } when this happens the item slots dont dissapear :(
When i put the Item Slot's Parent in the ItemSlotParent script it doesn't auto-detect all the item slots (this makes it unable to put items in those item slots) and it says that the script has no compiler errors
Solution: I wasn't paying attention :P I wrote "Onvalidate" instead of "OnValidate" This tutorial is actually the only one that worked for me even if it's an old tutorial, N I C E
Had a problem. PNG's need to be changed in the Inspector Texture Type (2D and UI). Don't know if that's a 2019 thing, but it was not covered in this vid.
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. ?
I think it has something to do with "private void OnValidate()" that command only works in editor. maybe change that to void Awake(). im new to c# coming across from java, but i think that should fix the problem.
I'm trying to integrate this UI tutorial with the Character Stats video you did. I deleted the example UI from the Character Stats example and began putting this in. All went well until I got to the Items.cs script. The issue is that public class Item in Character Stats is a Monobehave and the public class Item in the UI tutorial is a ScriptableObect. I'm trying to resolve this conflict but not having a lot of luck.
If you wanna do that, you should pretty much ignore/delete the example that was covered in the Character Stats tutorial (or the one that comes with the asset version 1.0.1). The next update of the asset (1.1.0) will come with the exact code that is covered in this Items & Inventory tutorial. In any case, if you keep following this tutorial, we do the integration with Character Stats on episode 3 ( ruclips.net/video/ez-YTf64Jn4/видео.html ). Feel free to ask if you have any more questions. Btw, link to the Character Stats asset: www.assetstore.unity3d.com/#!/content/106351
Still having issues with this one. In Inventory.cs at the line "itemSlots = itemsParent.GetComponentInChildren();" I am getting an error: "Assets/Character Stats/Example/Scripts/Inventory.cs(13,28): error CS0029: Cannot implicitly convert type `ItemSlot' to `ItemSlot[]'" EDIT: Figured out the issue: GetComponentInChildren should be GetComponentsInChildren.
Very very small detail, that is kind of "Unity's fault", if you will. You need to call the method "GetComponentsInChildren", plural Components (with an 's' at the end). This returns an array, instead of returning a single value, which is basically what the error is saying: you can't assign a single value to a variable that expects an array. You're calling the "GetComponentInChildren" version, singular Component (without an 's' at the end). Completely understandable, since that's such an easy thing to miss. I should totally have put some emphasis on that during the video. Edit: I'm sure you've already seen the link, but if you're interested in having a more direct conversation, you can join the Discord server: discordapp.com/invite/98YSpu2. I'm online most of the time :)
I'm really kicking myself for not finding these tutorials a while ago, amazing work! One question tho, do you have/can make/point me to a video on how to make the inventory artwork? Can anybody tell me what format/file extension they need to be?
I know it's late (7months late) but for anyone with the same problem I use Krita it's free and has lots of brushes, pixel art etc. Saving as a .png has always worked for me but unity probably supports .jpg aswell.
It is amazing! At the 8:16, if I make a change like this, will it also work? public void RefreshUI() { for (int i = 0; i < itemSlots.Length; i++) { itemSlots[i].item = null; if (i < items.Count && i < itemSlots.Length) { itemSlots[i].item = items[i]; } } }
Thank you for your awesome tutorials. Will you be making a part where you talk about persistance? Like saving character stats and inventory to file and then restoring them on new playthrough. I want to know what to do with Health stat in case character was damaged. For example when our Health = 1, and then we remove item that gives us +10 Health we will end up with -9 Health without neccessary checks. And the same case, when you equip item with +50% Health and character Health is at 5/10, will it become 7.5/15 or just remain 5/15?
Those are all really great questions. I am definitely planning to make a video about serialization/saving, not sure which part that's going to be, but it will come. In terms of adding and removing health through items, those mechanics ultimately fall on you to decide what you want to do in your own game, but here's some suggestions: MaxHealth is probably the stat that will get the bonuses, while CurrentHealth is a separate variable, more or less independent of MaxHealth. So when you apply or remove a MaxHealth bonus, CurrentHealth stays unchanged (unless removing the bonus would cause it to be larger than MaxHealth). You can do that by having a "public CharacterStat MaxHealth" variable, and a separate "public int CurrentHealth" OR You could extend the CharacterStat class to have a "public int CurrentValue" in addition to the original "Value", and apply whatever interactions you want between the two, since they're in the same class that would be easier to do.
Regarding items and inventory I think it is pretty strightforward and everything will be covered in next videos, as Character Stats videos cover almost every basic aspect of stats. I would like to propose some other topics I want to see from you (coz I like your way of making robust code, everything is decoupled and etc.), but it would rather selfish :)
I don't think it's selfish at all, I am open to any and all suggestions. I wanna make stuff that my audience actually wants to see! Doesn't mean I'll make everyone's request, but I will at least consider it :)
Great tutorial, i like the fast way You did the items. But i've got an error on the "item slot script" that says (error CS1014: A get or set accessor expected) and the function (private void OnValidate) is highlighted. I'm usid unity 5.6 version. What was Yours on this tutorial? Maybe the issue.
I was using version 2017.2.1 in this video, and updated to 2017.3 some episodes later, when it came out. But that should not be the cause of compilation errors. Could you show the code that is causing the issue?
Thanks for answering , this is the code. But somehow it fixed itself. Magic xD Probably because i had few scripts that were interfering. private void OnValidate() { if (image == null) image = GetComponent (); }
Hey dude ! I really like yours videos, but I have a issue.. When I drag one of my ScriptableObjects in my list of Item in Inventory Script, like you at the end of video, Unity crashes... Can you help me please ? Thx for yours videos, peace ! :)
Without more details it's impossible to tell what the cause of the crash might be. What version of Unity are you using? Have you checked if you did every step correctly according to the video? None of those should really be the cause of a crash, but who knows xD If still not working, consider joining the Discord server and uploading your project, so that I can take a look.
Kryzarel Yes, I have not been clear, sorry.. Actually, Unity doesn't crash, it does freeze. I'm using 2018.2, and I think it's could be a endless loop when I'm adding item to my list. I am not front of my script, I'll look more close tomorrow if it's really that, else I will talk to you on Discord. Thank you for your reply
I'm getting the error in my code 'The name 'Item' does not exist in the current context' Any help would be appreciated :) Here is my code: using UnityEngine; using UnityEngine.UI; public class ItemSlots : MonoBehaviour { [SerializeField] Image image; private Item _item; public Item Item { get { return _item; } set { _item = value; if (_item == null) { Image.enabled = false; } else { Image.sprite = _item.Icon; Image.enabled = true; } } } private void OnValidate() { if(Image == null) { Image = GetComponent (); } } }
The only reason that error happens is if the Item class can't be found. Let me ask some question to help track the source of the issue: Have you implemented the Item class yet? If you have, is it inside a namespace that you're not "using" in the ItemSlots script? Did you spell the "Item" class name wrong?
Would you mind clarifying what you mean? If you want to check the finished code, the link for the repository is in the description (you can download the entire project from there)
I apologize for my unclearness i was very tired, so basicly the itemslot script that is made to disable the sprite icons when the inventory slot isn't being used it only disables one and not the rest. Here is the code using UnityEngine; using UnityEngine.UI; public class ItemSlot : MonoBehaviour { [SerializeField] Image image; private Item _item; public Item Item { get { return _item; } set{ _item = value; if (_item == null) { image.enabled = false; } else { image.sprite = _item.Icon; image.enabled = true; } } } private void OnValidate() { if(image == null) { image = GetComponent(); } } } here is the refresh code private void OnValidate() { if (itemsParent != null) itemSlots = itemsParent.GetComponentsInChildren(); refreshUI(); } private void refreshUI() { int i = 0; for(; i < items.Count && i < itemSlots.Length; i++) { itemSlots[i].Item = items[i]; } for(; i < itemSlots.Length; i++) { itemSlots[1].Item = null; } }
okay so just finished your Tutorial on how to make charecter scripts.... However you didnt really show how to use it ? All i know i i got an amazing robust system ahah
Hey, I wanna apologize for not releasing a video last week, I had been working hard on a video to release alongside the Character Stats asset on the Unity Asset Store, but apparently Unity is taking 20 to 30 days to approve new assets now-a-days (yikes!). Really want both to release at the same time, so I ended up not posting anything :(
Hope you enjoy this week's video though :D
Man, thank you so much, I'm really glad you like it! If you have any suggestions or questions that you'd like me to cover in a video, feel free to let me know :)
Finally a tutorial that goes at a fast enough speed, other videos are usually 20-30 mins to not say much. Looking forward to listening to the whole serie!
Thank you for actually going through the process with explanations instead of just rushing through!!!
This is probably the most intuitive and simple inventory tuts, thanks!
Best tutorial in whole of the youtube, Fast and clear Good Job!!
Hands down the best tutorials on the internet, I've watched probably all others and i can say your way of presenting and actual code architecture are the best! Keep up the good work!
Dude how have I not found your videos before now?! These are great and exactly what I need!
Right now I'm starting this series. Hopefully it'll be good working inventory system for my game. I just wanna to say thank you for your work. You put links to he UI elements and to the source code, it's amazing. You are the best. Cheers!
Hi! hope this video isnt forgotten and my question gets answered:
is this tutorial compatible for unity 2019? more specificaly Unity 2019.4.17f1
because i was following the tutorial and everything was fine until 7:25
i got error CS0246.
i investigated a little about the problem and seems that it means that "ItemSlots[]" (and every derivate) doesnt exist
in case that this code isnt compatible with my current version, is there any way to replace this? What can i do?
Wonderful Video! Been looking all over for a good one that works and finally found one!
For some reason, at the inventory, i wrote GetComponentsInChildren yet it still writes the error CS0246 i shall say that it writes "the type or namespace name 'itemSlots' could not be found
Edit:found out
Great video, definitely helping me out tons on my current project! Will follow this series through for sure.
Just stumbled into these videos, Dude your tutorials are amazing! you really know how to elaborate on ideas and information better than most others ive seen. Keep up the awesome content man!
I am getting the following error when I try to save the Inventory Script, so it won't allow me to attach it as a component. Any ideas?
Assets\Scripts\Inventory.cs(13,61): error CS0246: The type or namespace name 'Itemslot' could not be found (are you missing a using directive or an assembly reference?)
Any idea why I am getting this? My code is identical to this video.
idk bro
I see loads of tutorials on how to make grid based inventory systems, but none on how to make list based ones like the ones you see in old RPGs such as Final Fantasy, where there were infinite slots for unique items and you could store something like 99 of the same item in one slot. I was wondering, could an inventory like this be adapted into that style of inventory? I'm very new to Unity and C#.
Great work the the tutorials. Most just read the code they are writing without explaining what is going on. Thank you for the detailed explanations it really does help. :)
In the inventory script, I'm getting this error -
Cannot implicitly convert type ItemSlot to ItemSlot[]
This is on this part of the code I have double checked all the scripts to make sure I dont have any screw ups.
private void OnValidate()
{
if (itemsParent != null)
itemSlots = itemsParent.GetComponentInChildren(); // this part im getting the error
}
nvm I hate my self
Haha, so I guess you figured it out. You need to use "GetComponentsInChildren" (plural Components) :P
lol yeah missed that bit :|
lmao I made this same mistake. I double checked again and again..... and was thinking if this error wad due to different version of studio!!!
@@Kryzarel thank you i was crazy , i couldnt find the mistake =) i forgot 1 s too lol
I'm surprised that this worked but now I'm spending forever trying to position my item slots so that's going to be fun. I'm happy that the inventory is fairly modular.
And I have done it! That's part 1 of 20 or so to finish adding the inventory system! It looks so good though and it's very modular.
better than even the biggest gamedevs tutorial
Great tut. You could use prefabs to the slots.
how did you get the perfect number for the spacing and cell size i use adobe illustrator
I cant get rid of this error: ''Cannot implicitly convert type ItemSlot[] to UnityEngine.Transform.'' The error is in this line: ''itemsParent = itemsParent.GetComponentsInChildren();
I would greatly appreciate it if someone here would help me.
You should not be assigning "itemsParent" to that get components call. It should be "itemSlots = itemsParent.GetComponents..."
@@Kryzarel Shit im stupid. Thanks a lot for the fast reply and sorry to bother you for something so minor. Suscribed and liked :) have a great day!
@@Kryzarel even though I did as shown in the video the whole line after itemSlots = "itemsparents.GetComponentInChildren();" is showing error, & the error code is Inventory.cs(13,37): error CS0029
fuck you all
@@1sudhan1 did you find a way to fix it?
How could implement the ipointerclickhandler in mobile touch?
Really digging the tutorial. Trying to follow along and I get this error on the Inventory script: error CS0246: The type or namespace name 'SerializedField' could not be found (are you missing a using directive or an assembly reference?)
Any help would be appreciated.
Seems you have a "d" too much. SerializedField should be SerializeField.
It won't let me drag my helmet into the items list under the inventory script on my inventory, somebody help I've been stuck for days. I have all the same code, but it still don't work.
Excuse me, when I pulled the object to inventory in the last step, item Slot got the image but enabled it did not open it. Why?
Having the same issue here,you have any answers ?
I have one issue, when adding my items to the inventory, the itemslots Image component does not enable, but rather stay disabled like its still null. Ive gone over the code for enabling and disabling and its perfect. I dont understand why it does this
void RefreshUI()
{
int i = 0;
@@jikrebelloza Did you ever fix this?
@@ItsMeNotYouSoHaha ```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour
{
[SerializeField] List items;
[SerializeField] Transform itemsParent;
[SerializeField] ItemSlot[] itemSlots;
private void OnValidate()
{
if (itemsParent != null)
{
itemSlots = itemsParent.GetComponentsInChildren();
}
RefreshUI();
}
void RefreshUI()
{
int i = 0;
for(; i < items.Count && i < itemSlots.Length; i++)
{
itemSlots[i].Item = items[i];
}
for(; i < itemSlots.Length; i++)
{
itemSlots[i].Item = null;
}
}
}
```
@@jikrebelloza Can confirm, having the int = 0; in the normal for loop breaks the code.
@@wonderful_investing7381 ok, very quick question: WHY?!?!?!?!?
Hey! Great video. Just a quick question. I cannot seem to drag my ItemSlotsGrid to the Inventory script component. Any way you can help me out?
The RefreshUI for loop make my Unity (the latest one) crash, i followed the exact code. Any idea why?
in item slots i keep getting this error :
NullReferenceExeption : Object reference not set to an instance of an object
} else
{
image.sprite = _item.Icon; // < right here
image.enabled = true;
}
when this happens the item slots dont dissapear :(
Starnight Studios same problem
I had same issue. Found that I had missed a = symbol in the (_item == null) had only one instead of 2 once I added a 2nd error vanished.
Thank you so much !!! It's works for me!
endless for loop while playing game may crush program . Am i wrong ?
When i put the Item Slot's Parent in the ItemSlotParent script it doesn't auto-detect all the item slots
(this makes it unable to put items in those item slots) and it says that the script has no compiler errors
Solution:
I wasn't paying attention :P
I wrote "Onvalidate" instead of "OnValidate"
This tutorial is actually the only one that worked for me even if it's an old tutorial, N I C E
@@XxDarnDragonxX thanks, I did the same thing
Had a problem. PNG's need to be changed in the Inspector Texture Type (2D and UI). Don't know if that's a 2019 thing, but it was not covered in this vid.
Yes, you have to convert to Sprite 2d UI, otherwise it will not work
this inventory I can put it in a database?
you are amazing! please keeping it
Is this series completed, or did it get abandoned? I see most of these inventory tutorials all end abruptly.
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. ?
I think it has something to do with "private void OnValidate()" that command only works in editor. maybe change that to void Awake(). im new to c# coming across from java, but i think that should fix the problem.
Very professional Video
how to make item stack and a max amount to the item on the inventory pls
That's covered in later episodes. Keep watching ;)
@@Kryzarel is this tutorial fitting Unity 2019.3.14f ?
I'm trying to integrate this UI tutorial with the Character Stats video you did. I deleted the example UI from the Character Stats example and began putting this in. All went well until I got to the Items.cs script.
The issue is that public class Item in Character Stats is a Monobehave and the public class Item in the UI tutorial is a ScriptableObect. I'm trying to resolve this conflict but not having a lot of luck.
If you wanna do that, you should pretty much ignore/delete the example that was covered in the Character Stats tutorial (or the one that comes with the asset version 1.0.1). The next update of the asset (1.1.0) will come with the exact code that is covered in this Items & Inventory tutorial. In any case, if you keep following this tutorial, we do the integration with Character Stats on episode 3 ( ruclips.net/video/ez-YTf64Jn4/видео.html ). Feel free to ask if you have any more questions.
Btw, link to the Character Stats asset: www.assetstore.unity3d.com/#!/content/106351
Still having issues with this one. In Inventory.cs at the line "itemSlots = itemsParent.GetComponentInChildren();" I am getting an error: "Assets/Character Stats/Example/Scripts/Inventory.cs(13,28): error CS0029: Cannot implicitly convert type `ItemSlot' to `ItemSlot[]'"
EDIT: Figured out the issue: GetComponentInChildren should be GetComponentsInChildren.
Very very small detail, that is kind of "Unity's fault", if you will. You need to call the method "GetComponentsInChildren", plural Components (with an 's' at the end). This returns an array, instead of returning a single value, which is basically what the error is saying: you can't assign a single value to a variable that expects an array.
You're calling the "GetComponentInChildren" version, singular Component (without an 's' at the end).
Completely understandable, since that's such an easy thing to miss. I should totally have put some emphasis on that during the video.
Edit: I'm sure you've already seen the link, but if you're interested in having a more direct conversation, you can join the Discord server: discordapp.com/invite/98YSpu2. I'm online most of the time :)
Nice, you figured it out even before I answered. Kewl :D
I'm really kicking myself for not finding these tutorials a while ago, amazing work! One question tho, do you have/can make/point me to a video on how to make the inventory artwork? Can anybody tell me what format/file extension they need to be?
I know it's late (7months late) but for anyone with the same problem I use Krita it's free and has lots of brushes, pixel art etc. Saving as a .png has always worked for me but unity probably supports .jpg aswell.
It is amazing!
At the 8:16, if I make a change like this, will it also work?
public void RefreshUI()
{
for (int i = 0; i < itemSlots.Length; i++)
{
itemSlots[i].item = null;
if (i < items.Count && i < itemSlots.Length)
{
itemSlots[i].item = items[i];
}
}
}
Great video keep it up. :)
Thank you for your awesome tutorials. Will you be making a part where you talk about persistance? Like saving character stats and inventory to file and then restoring them on new playthrough. I want to know what to do with Health stat in case character was damaged. For example when our Health = 1, and then we remove item that gives us +10 Health we will end up with -9 Health without neccessary checks. And the same case, when you equip item with +50% Health and character Health is at 5/10, will it become 7.5/15 or just remain 5/15?
Those are all really great questions.
I am definitely planning to make a video about serialization/saving, not sure which part that's going to be, but it will come.
In terms of adding and removing health through items, those mechanics ultimately fall on you to decide what you want to do in your own game, but here's some suggestions: MaxHealth is probably the stat that will get the bonuses, while CurrentHealth is a separate variable, more or less independent of MaxHealth. So when you apply or remove a MaxHealth bonus, CurrentHealth stays unchanged (unless removing the bonus would cause it to be larger than MaxHealth).
You can do that by having a "public CharacterStat MaxHealth" variable, and a separate "public int CurrentHealth"
OR
You could extend the CharacterStat class to have a "public int CurrentValue" in addition to the original "Value", and apply whatever interactions you want between the two, since they're in the same class that would be easier to do.
Thank you for answer, extending base CharactedStat would seem to me the best way to handle that problem
Glad I could help! If there's anything else you wanna ask, feel free. Or anything you'd like me to cover in a video too :)
Regarding items and inventory I think it is pretty strightforward and everything will be covered in next videos, as Character Stats videos cover almost every basic aspect of stats. I would like to propose some other topics I want to see from you (coz I like your way of making robust code, everything is decoupled and etc.), but it would rather selfish :)
I don't think it's selfish at all, I am open to any and all suggestions. I wanna make stuff that my audience actually wants to see! Doesn't mean I'll make everyone's request, but I will at least consider it :)
*FIXED* Nice video!
Great tutorial, i like the fast way You did the items. But i've got an error on the "item slot script" that says (error CS1014: A get or set accessor expected) and the function (private void OnValidate) is highlighted. I'm usid unity 5.6 version. What was Yours on this tutorial? Maybe the issue.
I was using version 2017.2.1 in this video, and updated to 2017.3 some episodes later, when it came out. But that should not be the cause of compilation errors. Could you show the code that is causing the issue?
Thanks for answering , this is the code. But somehow it fixed itself. Magic xD Probably because i had few scripts that were interfering.
private void OnValidate()
{
if (image == null)
image = GetComponent ();
}
Ok, glad it got magically fixed, then! xD
Hey dude ! I really like yours videos, but I have a issue.. When I drag one of my ScriptableObjects in my list of Item in Inventory Script, like you at the end of video, Unity crashes... Can you help me please ?
Thx for yours videos, peace ! :)
Without more details it's impossible to tell what the cause of the crash might be. What version of Unity are you using? Have you checked if you did every step correctly according to the video? None of those should really be the cause of a crash, but who knows xD
If still not working, consider joining the Discord server and uploading your project, so that I can take a look.
Kryzarel Yes, I have not been clear, sorry.. Actually, Unity doesn't crash, it does freeze. I'm using 2018.2, and I think it's could be a endless loop when I'm adding item to my list. I am not front of my script, I'll look more close tomorrow if it's really that, else I will talk to you on Discord.
Thank you for your reply
Just found your channel, great tutorial , nice talking, so lets subscribe:D
THAAAAAT'S veeeery good
hooly shet
very nice
I'm getting the error in my code 'The name 'Item' does not exist in the current context' Any help would be appreciated :)
Here is my code:
using UnityEngine;
using UnityEngine.UI;
public class ItemSlots : MonoBehaviour
{
[SerializeField] Image image;
private Item _item;
public Item Item {
get { return _item; }
set {
_item = value;
if (_item == null) {
Image.enabled = false;
} else {
Image.sprite = _item.Icon;
Image.enabled = true;
}
}
}
private void OnValidate()
{
if(Image == null)
{
Image = GetComponent ();
}
}
}
The only reason that error happens is if the Item class can't be found. Let me ask some question to help track the source of the issue: Have you implemented the Item class yet? If you have, is it inside a namespace that you're not "using" in the ItemSlots script? Did you spell the "Item" class name wrong?
Ah, it seems I named the 'Item' class 'Items' so all I had to do was re-word it, thanks for your reply and help, much appreciated.
for me it only disables one slot..
Would you mind clarifying what you mean? If you want to check the finished code, the link for the repository is in the description (you can download the entire project from there)
I apologize for my unclearness i was very tired, so basicly the itemslot script that is made to disable the sprite icons when the inventory slot isn't being used it only disables one and not the rest. Here is the code
using UnityEngine;
using UnityEngine.UI;
public class ItemSlot : MonoBehaviour {
[SerializeField] Image image;
private Item _item;
public Item Item {
get { return _item; }
set{
_item = value;
if (_item == null) {
image.enabled = false;
} else {
image.sprite = _item.Icon;
image.enabled = true;
}
}
}
private void OnValidate()
{
if(image == null) {
image = GetComponent();
}
}
}
here is the refresh code
private void OnValidate()
{
if (itemsParent != null)
itemSlots = itemsParent.GetComponentsInChildren();
refreshUI();
}
private void refreshUI() {
int i = 0;
for(; i < items.Count && i < itemSlots.Length; i++) {
itemSlots[i].Item = items[i];
}
for(; i < itemSlots.Length; i++) {
itemSlots[1].Item = null;
}
}
Did you add the script to all item slots? Did you check if the Inventory has all the references to all the item slots?
Yes it has all the slots and the script is in every slot
I fixed it, i watched the video in pretty low quality and i saw a "i" as a "1" its fixed now and working, thanks for your time and help though! :)
very good tut
okay so just finished your Tutorial on how to make charecter scripts.... However you didnt really show how to use it ? All i know i i got an amazing robust system ahah
the MediaFire link launches an Ad intrusion attack.
Can you explain what you mean? I don't personally see anything wrong when I open up the link.
/Inventory.cs(15,28): error CS0029: Cannot implicitly convert type `ItemSlot' to `ItemSlot[]'
did the same thing, look carefully! its GetComponentsInChildren not GetComponentInChildren just add an s
@@daryll4645 Thanks. I hate missing spelling errors.