I just want you to know your tutorials are not only helping me make an inventory system, but helping me to learn a LOT of stuff around it as well.
Here after watching the first video, I love the way you explain certain things, it makes it really clear (although I'm still pretty new so I don't really understand most things yet... hopefully, that'll change) anyway just want to say thank you. This is an amazing series and I intend to watch the whole playlist.
As a non-English speaker, Other lectures are hard to listen. However, this lecture is well explained and easy to understand to your voice full of passion and confidence.
The quality of the lecture is very good. I'm glad I searched for the ScriptableObject Inventory lecture before implementing the inventory function as "Playerprefs". (It's terrible just to imagine.)
Best lecture ever, Best teacher ever. I shared it to another developer. Have a great day.
You are amazing at explaining everything, you don't have a clue on how much you're helping me, thank you so much
Been following along and just wanted to say thank you for providing us with great Unity content. Greetings from Norway 👍👍👍😃
Thank you for putting out these videos, they are excellent, straight to the point and I like that you started from scratch in Unity with these tutorials. Because of this I can understand what each part of your code does a lot easier. Learnt a lot so far!
What a great tutorial to learn not only the inventory but also the basics of the save function!
Great ! no problems at all working very smoothly so far about to start the next episode !
these are really valuable tutorials that are a must for developers. If you want to make a real game then these kind of videos are important
Thanks a lot for this tutorial! I like the idea of scriptable objects but was a bit stuck with the saving part. Ended up with some wicked text replacement within the json string. Those After/BeforeSerialization methods are a blessing.
Remarkable!,
Ending the day with a new part from this tutorial is very relaxing and teaching.
Thanks man
yeah, not many people realize how important it is to securely write out objects and write them in for MMORPGs thank god you made this. I was using referencde structs to populate my games items before i saw this and saw the callback receiever. now, im gonna experiment with this for another week or two and see if i can get result i like. xD
Another great video! Loving this tutorial series.
super big thanks!!
i love your content! you make these really easy to understand. 😊💕
Man, there are so many inventory issues that have been bothering me for 2 weeks, today I'm so lucky to have found your video. I like the way you explain when writing code, as there are many techniques if you don't explain, then I wonder: how can I learn this on my own? I love you! Wishing you many interesting experiences in life!❤
I don't normally comment on videos but I feel in this case I have to. You are by far one of the best tutors in C# in Unity that exists on UA-cam. You explain clearly what you are doing and why and in such a way I can actually understand you; and it makes a lot of sense. However, I am experiencing the same problem as elcamp3 in that my Save and Load procedures only work if I use them as soon as the game starts (with no items in the Player Database). Once I collect some objects they no longer fire. Will continue to try and solve the issue (I hate to give up) but any information you can provide will be much appreciated. Keep up the excellent tutorials, I look forward to finishing this project.
Are you getting errors?
Be easier to help you on discord, so feel free to join it!
Thanks, but I solved the problem. There was nothing wrong with my code, I can't believe I'm going to admit this. When I used my player to collect some objects the focus was on the Scene View so none of the keys would work in game view. Once I switched focus to Game View everything worked. That is a mistake I will not be repeating.
Thank you very much for this it was really helpful, now I'm going to continue onwards with the series.
Following along trying to understand some of the concepts, but I'm quite new in programming so this one was tough - at least it works :) I have no idea what most of this code means for now, ill try my best to understand it. Anyways the best inventory system I've seen so far, thanks for sharing your knowledge, im very grateful!
Damn, the item database solution is brilliant! I can think of a number of improvements to it such as creating different database assets for different item types, but I think this is the solution I'm going to go with. Thanks!
Finished implementing this last night. Wound up making a base ItemDatabase so that I could extend it with specific item types.
This video is very useful and didactic, please make more videos like that!
Very helpful. Thank you so much for making these videos.
best tutorial i've ever watched so far!
These tutorials are awesome! Thank you!!
I've been programming 20 years but I've always found Unity intimidating. These tutorials are perfect, better than the selection on Unity Learn Premium.
Really glad your enjoying them!
Also awesome to hear i appreciate it :)
I think, thank you for these videos. I'll have to watch about 19 other tutorials to understand most of what you're talking about but it looks far beyond what I will need.
Thanks a lot. This helped me a lot in understanding to write my own scriptableobject. Great stuff. It's a shame you no longer making new videos.
Amazing and informative tutorial! Recommend 10/10 would buy again... :P
This is such an amazing tutorial - I hope you dont mind, but If I could make a suggestion... to do a code review off the classes...
it would help with debugging... (often downloadble projects dont nessasrily match what is happening in each stage, which makes it tricky to see where Ive gon wrong...) None the less this is really the best tutorial Ive seen so far on this topic - and Im so thankful for it!
uff gotta watch it again. i´m new to all of this but thx for the video!
Thanks, it works on android. For those who want to use it on android, you just need to plug it to a save and load function
Super Duper good! Love your tutorial ~
T H A N K Y O U SO MUCH!
I've learned SO SO much from just these 2 videos so far!
Learned nothing yet, but!..
REAL learning gonna begin when I'll try to make this system fit for my game
Always excited to watch your videos man!
What are we seeing next btw?
Im going to do a few more videos on this series, i want to show how to make an equipment screen and a bank
Im also considering making a combat system and combining the leveling/inventory/and combat system videos into a game in another video (but dont hold me too it)
Im also following the new dots networking and may consider doing videos on that down the road.
Coding With Unity Oh man, this is exciting. Really loving the RuneScape related videos. Rarely I find videos with inventory system or any system that relates to RuneScape.
Great game to get inspired on various systems. I am really liking Dots too btw. Are you working on any real project right now?
@@CodingWithUnity Would you be willing to try, or show, some sort of basic crafting system. Combining two or more items to create a third item?
That should be simple to do, ill think about it and see if i can make a video on it near the end of this series!
I'm a little confused about where the save files are created? It seems the save file when playing inside the editor is different than with a build. I'm on a Mac - and when I play in the editor it gets saved to Library/Application Support/DefaultCompany/ProjectName/. But the Build seems to be saving elsewhere because if I delete that file at that path, and create a new one with the build, it doesn't show up in that folder. The saving/loading functionality IS working though. Any idea where the build is saving the file? I'm so confused.
amazing course!
Just for notice: it's a myth that the + operator for strings is less performant.
Somehow everyone seems to believe that, but it's not true. It's actually in most cases the most performant.
The myth comes from when you do iterations where you add stuff to a string, it can take a lot of time, as every iteration it creates a new string, but if you just do it inline, the compiler knows it and does it in a optimal way.
Exactly. Even Microsoft recommends using the + operator. Basically, by using the + operator, the C# compiler will evaluate which concatenation method to use based on performance. Sometimes, you just have to trust the compiler and write simple code
@@MyCiaoatutti I Believe microsoft recommend using the String Interpolation operator $"{variable} {variable2}".
The performance hit is due to heap allocation and unity has a poor outdated garbage collector, so it's more unity specific
Absolutely disagree using + generate more garbage collection. There's a better solution is using ZString in order to use concat, direct text without any allocation, Join and Format. Each + operator allocate more and more garbage until your game start to have some stutters and lag
Thank u for this wonderfull tutorial.
very good stuff, it'll be even better if you can explain more XD
At 14:30 you could use using FileStream. (Thus not needing to call Close).
And Use Path.Combine instead of string.concat().
Thanks for your videos. I am learning a lot with these.
A suggestion would be, instead of using the double Dictionary we can just use the index i of the items array.
the code for this in the ItemDatabaseObject.cs would then look like this:
public ItemObject GetItemById(int _id) {
if (_id >= items.Length) {
return null;
}
return items[_id];
}
Just posted a comment asking if there was any real reason not to do exactly this. Seems over complicated and unnecessary but thought I was maybe missing something...
@@chrisflynn5192 If you want to use GUID as your ID, you won't access your array by index. It works here because int _id is an "int". And the ID of the object are their indexes.
If you have an Item[5] and one of your item has 123 as it ID. Accessing items[123] will throw an exception with ArgumentOutOfRange.
While with a dictionnary you could have
[123] : Item
[235] : Item
[1] : Item
or if you key is a string
["wood"] : Item
["water"]: Item
["somethingelse"]: Item.
Then you access your item dictionnary with : MyDictionary[Item.Id].
ok so i have a problem the inventory is not showing the items when i build it but runs perfectly in editor mode help!
this dude is bonk and all over the place... trying to follow the tutorial... good explanations but crazy execution O_o
how can i save multiple databases? cuz i can create worlds, several worlds in which the save path is different. so if i'm in the "New world 1" that's my save path and the game loads my data which is saved in the "New World 1" folder.
I may be doing something wrong but when I pick up an item and save, then pick up 1 or more items of a different type and then finally reload it seems like the items that isn't saved dosen't get removed VISUALLY...It's like it UI dosen't update when going to remove slots it just adds them
hey when i press enter multiple times, it loads and displays the slots over the existing ones, how can i fix this ?
Hi! Can i make, that saving system is working every second(update()), and load the inventory in start?
I’ve been trying it you’re video helped so much thanks I tried many other tutorials but never learned anything especially brackys but i can’t register the items do you know what’s the problem?
ok so this is a old video but ive followed everything perfectly but i cant get the save and load from pressing "space" and "enter" to work. i do have a character controller that uses the "GetKey("Space") for jumping in my character controller so would that be the problem?
sory I want to ask
Why when I build the pc, and run the program it does not show the item in the inventory
but in the unity editor run ok
i have facing a problem on Load function when i put the load function on OnDisable function all the save data are deleted! can someone help me please?
Thank you!!
Hello, I`m new to Unity , I want to ask if add an Item_ID on the Item Scriptable Objects, then put each Item an unique ID, is it work for not adding the database section ??
is there not a method we can add to the ItemObject which automatically appends itself to the database when it's created so that we don't have to manually add each item? I would like to make it more designer friendly.
when i build and run , in the game save&load dont work, and my player dont interact with objects :/
can someone help me with that?
In unity all works good. but in game no :(
So in the editor everything works perfectly, and when i build it completes with no errors, and saving/loading works. However, my player when walking over the item prefabs, doesn't pick them up or add them to the inventory.
If I build the game with items already manually added to the player inventory, then it works as intended.
Again, only for clarification, if I hit play in the editor with the player inventory empty it works, but will only work after built if the inventory has items already in it.
Would anyone know why this happens? I've checked my code with the tutorial a few times and cant see any difference.
I know this is one year after you posted this, but in case anyone else has this issue, make sure your path is correct to your database after you move it to the resources file! In your “OnEnable” method in your InventoryObject script, the path file should be “Assets/Resources/Database.asset”.
Hopefully this helps at least on person!
Thanks a lot.
Thanks!
Thank you for nice tutorial.. please do drag and drop item from Inventory to world.. thank you.
how to save using cloud storage like cloudonce? did anyone know? please im stuck around 5 month right now for android
it is okay to use json to save and load your game? i mean i want my data more secure to prevent hacked or changing the data
Everything seems to be working besides when i go into build i no longer can pick up the items, but the save and load works :)
I'm 2 weeks into Unity & coding so this is over my head but somewhere before you changed the database from public to private, the item ID paramater in player inventory no longer works in identifying which item you are loading out your inventory with. If you hit play while your player inventory's load-out is set to container size at 0 and or items set to none, picking up items while colliding won't work. In other words, you have to populate your player inventory with every item before hitting play otherwise you won't be able to pickup the said item.
hey man great vid really helpfull when will you do the vid to move the items from slot to slot
There should be a vid in the series called item swapping or something like that
Hey So I just cant seem to find out how to save Scriptable Objects that are instanciated in a scene
what is the best type of inventory system that allows the same item multiple times with different stats in a players inventory thats saveable??
I have been using scriptable objects for the longest time since it allows for just creating the object over again and allowing to change the stats of those items but to make it so it saves feels impossible
I Use CreateInstance does this work with this??
I exported the project and they everything broke, i can only collect if i have the item allready, save doesn't work anymore, and so on :( and it's not only in the build, it's also in the preview
Hello, I've been following these tutorials, It Was Amazing! but I have one problem, what about when removing items from inventory how do we update the display when it was all out :3
Hey there, loving these tutorials. I've made an inventory before but not had much experience with scriptable objects. Loving them already though, and they seem straight forward so far.
I did have a query regarding your database though. Why do you need the dictionary? If you are populating the ItemObject[] in the editor and you make sure that the ItemObject.id is the same as its index in the array surely you can access it directly using item[id]. You could then just store the database object in your resources folder. Am I missing something here?
i totally agree with you, and that was exactly my approuch, but with a few changes, since i'm not leaving the item array and the dictionary, which i named mappedIds, as public, i made a method for the DatabaseObject: GetItem(int id) { return item[id]; } and another for GetId(ItemObject item) { return mappedIds[item]; }
I'm having a bizarre issue with this system where InventoryObject.OnAfterDeserialize is always throwing a null reference exception. I did some head scratching and googling around, and it looks like it *might* be a Unity issue where references aren't kept after deserialization. Has anyone else had this issue? Unfortunately, I'm not experienced enough to code up a workaround.
Invalid operation exception. You are trying to read input using the UnityEngine.Input class, but you have switched active input handling to input system. Why this error ?
so after i built the game the inventory just stopped woking and I have no idea why it doesn't even work from the inspector
Really amazing tutorial!!! tysm for making the effort:D, I just had one question: when saving for example my inventory with 2 items inside, then picking up another item and loading, all 3 items show up, not only the 2 saved ones. Is that meant to happen?
Hello, thank you for this series! I really apreciated! :D I have one question. Where is the save folder located? I dndn't really understand this part and I don't find the save folder. Is that normal? Because when I wrote something in a .txt, I see the .txt beind added in the folder, but not this json.. Thanks you!
Edit:
I found the file by addind this in the Save function: Debug.Log(Application.persistentDataPath);
Could you please help me?
Inventory works, even if I quit and reload the game. But if I update my app(mobile game), it cannot repopulate the items. Amount of the items are correct but it doesn't recognise what item it is.
Is there a work around for this? I tried to use an array, but it break the system and loading didn't work. I am guessing the reference from the dictionaries break => cannot repopulate
Or the database reference breaks and no loading (still using the resource system)
It definitely sounds like your database reference is the issue to me. If it is then none of your ItemObject assets will be included in your build. Are you loading your database using Resources.Load?
Works 10/10, on Windows 10.
Awesome series, it is for me so complicated, even throught the fact, that I am into programming for 2 years (I know its nothing but still). Only one question and that is at 13:35, how exactly did you attached FileSteam to that string???
Not sure if this is what u might be looking for but, just curious if u added the using System.IO; at the top. Plus the save path was is supposed to be typed in by you on the inventory scriptable object inside the inspector. Will only work if that scriptable object is in that location. Hope this was what u were looking for or talking about.
I don't know if anyone will respond, but I'm having a problem where I can save inventory but can't load it. Please, if anyone knows anything let me know.
Your videos are so great and so helpful!!
However I seem to have an issue. When changing the ID like you do at 11:41 my Item does not update? I have followed your examples to the letter... Please can you assist?
Figured it out, never had ISerializationCallbackReceiver on my InventoryObject.cs
Been working through this, but inn getting an issue that I simply cannot figure out the reason behind. Essentially, when I boot up the first scene everything works fine. On load it will add the item slots and game objects to the dictionary and update it as expected. On the second scene this works too. But when I go from the second screen to the first screen again, through breakpoints I can see that on load it correctly assigns the slots to game objects. But between the scene loading and me picking up a new item, the values in the dictionary just become null. Have you ever encountered an issue like that with this setup?
help pls build and run is to long loading maybe i skip making folder to other asset script
When I load in my build before saving in my build, it does not load the save from my editor. It instead spams my debug log with errors and infinitely instantiates inventory slots. What could be the error? How could I fix?
It sounds like some code is in the wrong spot, but switching ISeralizationCallback with Onvalidate might help
I encountered this issue as well. The reason it was happening was because I had the [System.Serializable] tag in front of the database variable. But the same issue would occur if it was public. Just make sure that the variable is private and cannot be read by unity.
Can you help please...So far, tutorial going well, except for the Save & Load which is not working at all. I have tried assigning different Key Codes, but it's just not happening. Any suggestions/help would be appreciated thanks.
i have error, when i try to build and run i got two errors, one says:
Assets\scripts\inventory\Scriptable objects\Inventory\Scripts\InventoryObject.cs(21,13): error CS0103: The name 'databse' does not exist in the current context
and second says:
Error building Player because scripts had compiler errors
Hey so ive been recently following this tutorial but it always brings up an error with the resource folder when trying to build. any chance things changed since then?
Yes, I get rid of the resource folder around video 4 I believe, cant remember for sure. But it doesn't stay long and i start doing build test at the end of the videos in one of the future videos on
@@CodingWithUnity Thank you so much. Especially for responding so quickly. Your tutorials have been amazing so far and cant wait to get through the rest.
Hello, thanks for the tutorial, it's been a lot of help to me. Question: How would you remove an item from the inventory using this system? I'm making a simple unlock system using an item (a key) and then the idea is to discard the item. How can I access to the container's items through code? Thanks in advance!
What did you clicking at the FileStream at 13:48? I dont have Visual Studio so I dont know what you activated.
i cant see anythignt hat i clicked, just that i used string.concat (which for reference, its better to do `$"my concated strings number is {myInt}"`
Couldn't you use [SerializeField] above your ItemDatabaseObject variable declaration at 19:00 instead of the OnEnable? It would allow you to still set and change the value through the editor and may work better. I'd think it would make things smoother if you moved paths around.
His goal was to keep the database Deserialized so using SerializeField would have rendered the point moot.
i build it and run load is not working database is keep reseting to no database
OnAfterDeserialization of InventoryObject running before the OnAfterDeserialization of ITemDatabase. which Throw error.
I am getting an error that says keynotfoundexception, it says line 14 and 35, but there doesn't seem to be an issue in those lines? (it happens when the player touches the item)
Try this:
In the for loop for get item,
Write:
If(database. Get item. Containskey(container[I]. ID)
//populate that item
Ok, but how do you Delete the saved data?
i can't pick items unless it already in the database
Can't you use System.IO.Path.Combine() in place of the string.concat functions and it automatically handles directory (folder) separators for different operating systems? you should also wrap the FileStream with using() so that it automatically handles resource clean up on exceptions.
Hi Matt. could you please tell me the line of code? I cannot handle it. FileStream file = System.IO.Path.Combine(Application.persistentDataPath, saveData)); is not correct
@@magictimm4090 I *think* he put "using System.IO;" at the top of the InventoryObject.cs with just using a rightclick and a menu and never scrolled up to the beginning of the code so you might have missed it. I only know cause I missed it, too, and typed it in manually.
This has been a great tutorial so far but I'm still receiving the KeyNotFoundException error. I've changed the script execution order to ensure the ItemDatabase script's OnAfterDeserialize() callback is called first and added checks to the InventoryObject but still receiving the same error. The ItemDatabase script is simply not recognizing the object key. Any suggestions?
@@dattoproduction4450 @Bryan Lopez
You must have put the code:
getId = new Dictionary();
getItem = new Dictionary();
for (int i = 0; i < items.Length; i++)
{
getId.Add(items[i], i);
getItem.Add(i, items[i]);
}
into the OnBeforeSerialize function instead of OnAfterDeserialize.
Also, make sure this code:
for (int i = 0; i < container.Count; i++)
container[i].item = database.getItem[container[i].id];
is also in OnAfterDeserialize.
@@chosenone3 Doesn't works, OnBeforeSerialize is not necessarely called before OnAfterDeserialize
idk if im just tired because its 2am but... i added in the save and load features and I can no longer pick up the items in my game. If this video is still active, someone help?
Around the middle of this tutorial, I started getting the error message "UnityException: ToString is not allowed to be called during serialization, call it from OnEnable instead."
Has anyone else figured out how to solve this? I'm unable to build because it won't compile.
i had to add
public void OnEnable()
and add all the code under that instead. but i had to leave the other two public void's as well just with nothing in them then the error went away
Awesome video! I'm a bit confused as to why when I save the Items and reload them they show all the same icon, instead of the different variations of the icons, example( i pick up 3 first aids, 3 canned food, 3 water bottles. then i hit space to save, quit, reload, try to load my items and it says i have 3 first aids, 3 first aids, and 3 first aids! it still shows in 3 different columns but the icons all change to the original texture which is the First aid.
Does not work because the OnAfterSerialize call order is random, sometimes i just get an error because the InventoryObject is trying to access an empty dictionary inside of the ItemDatabaseObject
Same here. It's always null database because OnAfterSerialize will run before OnEnable.
This is a great series! Easy to follow and gives solid information. Also like how you are layering the concepts but not getting too far into the extra details.
Thank you! :)