Interesting ways you should use collections in your Unity3d game development - fixed audio

  Рет қаралды 28,886

Jason Weimann (GameDev)

Jason Weimann (GameDev)

Күн бұрын

Пікірлер: 80
@aronlinde1723
@aronlinde1723 5 жыл бұрын
For those looking for the next cool thing to pick up with Dictionaries. Look at using a Dictionary with a Command pattern. and you can pass in an Action by type or Type and it will return a method you can then fire. This is how you can make quickly variable Command patterns that are manageable versus monster smelley Switch trees.
@Unity3dCollege
@Unity3dCollege 5 жыл бұрын
Fixed the audio, thx josh for fixing it and everyone else for calling it out :)
@ggjosh3296
@ggjosh3296 5 жыл бұрын
Unity3d College anytime!
@VaporTrap
@VaporTrap 5 жыл бұрын
so much better!!!! gratz
@VaporTrap
@VaporTrap 5 жыл бұрын
@@DemaGraphexTube Hi I'm a noob myself but I believe PlayerPrefs only accepts floats, ints, and bools by default. I created a class that converts a list into serialized playerpref entries and another class that converts the entries back into a list, i'm sure you can do something similar for arrays
@VaporTrap
@VaporTrap 5 жыл бұрын
@@DemaGraphexTube sure thing bud are you on discord? grapemane#0012
@VaporTrap
@VaporTrap 5 жыл бұрын
@@DemaGraphexTube yes. in the same class i have public void Save() { /// --------------------- SKILLS SaveFloatList(PlayerController.instance.XP, "SkillXP", 50); SaveFloatList(PlayerController.instance.level, "SkillLevel", 50); /// --------------------- CURRENCY SaveFloatList(PlayerController.instance.prestigePoints, "PrestigePoints", 50); SaveIntList(PlayerController.instance.itemsEaten, "ItemsEaten", 50); SaveFloatList(PlayerController.instance.chickensEaten, "ChickensEaten", 8); SaveFloatList(PlayerController.instance.currencyOwned, "CurrencyOwned", 50); SaveFloatList(PlayerController.instance.upgradesOwned, "UpgradesOwned", 50); } and private void LoadAll() { /// --------------------- SKILLS LoadFloatList(PlayerController.instance.XP, "SkillXP", 50); LoadFloatList(PlayerController.instance.level, "SkillLevel", 50); /// --------------------- CURRENCY LoadFloatList(PlayerController.instance.prestigePoints, "PrestigePoints", 50); LoadIntList(PlayerController.instance.itemsEaten, "ItemsEaten", 50); LoadFloatList(PlayerController.instance.chickensEaten, "ChickensEaten", 8); LoadFloatList(PlayerController.instance.currencyOwned, "CurrencyOwned", 50); LoadFloatList(PlayerController.instance.upgradesOwned, "UpgradesOwned", 50); } and I call those 2 functions when the player clicks save or load
@dwried
@dwried 2 жыл бұрын
Arrays, lists, hashsets, dictionaries, stacks, queues... Nice video. There's so many ways to deal with data it's good to have the correct tool for the job. I wouldn't want to use a sledge hammer on a finishing nail.
@stefano4993
@stefano4993 5 жыл бұрын
I followed your instructions... my mom just published her first game!
@Alluvian567
@Alluvian567 5 жыл бұрын
REAL WORLD EXAMPLES!!! Music to my ears man, and something that would just be sarcasm out of so many 'build a game in 10 minutes!!!' youtubers.
@doudar41
@doudar41 2 жыл бұрын
Queue was used in Unity Beginners Code Kit to limit audioSources to play as I understand. They have a singleton that instantiates limit number of prefab audioSources for particular group of sounds for example player. And use queue to remove first audioSource in queue and add it to end of the same queue when new sound is going to be to played.
@TheFlyJunky
@TheFlyJunky 4 жыл бұрын
Jason you have THE BEST unity tutorial content on the internet
@rickloyd8208
@rickloyd8208 5 жыл бұрын
Ideas for future episodes: serialization (lists and dictionaries) and coordinates (world, local, calculations and conversion of mouse pointer)
@ShackMan
@ShackMan 5 жыл бұрын
Another very useful video! I think it's great that you prepare everything and don't waste time typing line by line.
@leokamikkaze20
@leokamikkaze20 5 жыл бұрын
watching any video from this channel is not a waste of time, no matter how experienced you are. Keep the great working!
@Hennadii_S
@Hennadii_S 2 жыл бұрын
This topic is too complicated for me, for now. But i watched it with greate interest, and save for later - i will defenetly watch it at least one more time, when I'll became more familiar with collections in C#. Thank You for this video, and all videos, You have done, they are greate! Very interesting, informative, useful and well done.
@thomasanderson1416
@thomasanderson1416 5 жыл бұрын
Nice explanation. So a HashSet is basically a List with unique items only. [Add, Remove]. Dictionary, self-explanatory. [Add, Remove]. Stack is LIFO (Last in first out) - [Push Pop]. Queue is FIFO. [Enqueue, Dequeue].
@andyBorko
@andyBorko 2 жыл бұрын
Awesome! The best explanation of using collections! Thanks!
@peterquill726
@peterquill726 5 жыл бұрын
Hashset is actually what I need in my project lol, why havn't I heard of it before is beyond me.
@tonychristney2728
@tonychristney2728 4 жыл бұрын
Relative performance matters as well. Searching a large list for an element is slower than a hash set or a dictionary, but accessing an element in an array is crazy fast by comparison. If you can use an array or list where the key is just the array index, performance will be much, much faster than a dictionary. In my experience with Unity and C# in general, the list has to get pretty big before a Dictionary starts to outperform it. Like a couple dozen items or so.
@MsRedNebulaPlays
@MsRedNebulaPlays 5 жыл бұрын
Thank you! This is a very useful video. Coming from a PHP background, the different types of collections in C# had me a bit puzzled, and this cleared everything up.
@Unity3dCollege
@Unity3dCollege 5 жыл бұрын
Glad to hear it was helpful. Collections are huge and really confused me for the first couple years. :)
@DaniArkadia
@DaniArkadia 4 жыл бұрын
Super useful stuff, thanks Jason.
@DB-pt6zj
@DB-pt6zj 5 жыл бұрын
Man I accidentally had playback at .75 speed. I thought you were drunk AF.
@Juan-lj4pi
@Juan-lj4pi 4 жыл бұрын
Lmao
@purpl3grape
@purpl3grape 3 жыл бұрын
only way to code
@jugibur2117
@jugibur2117 3 жыл бұрын
Very helpful, as always. Thanks Jason!
@diliupg
@diliupg 5 жыл бұрын
Audio sounds much better than before but you still reduce the harshness by making a dip in the frequencies around 1000 - 2000 Hz. WIll make your voice a lot smoother.
@Unity3dCollege
@Unity3dCollege 5 жыл бұрын
I'll give that atry, thx!,
@simoncodrington
@simoncodrington 4 жыл бұрын
Great video mate, nice simple use case for how to use hash sets. Cheers
@ahmedthebest
@ahmedthebest 5 жыл бұрын
Thank you for fixing the audio please use a dark script editor I can see the code
@anotherplatypus
@anotherplatypus 5 жыл бұрын
Initially the idea of KZbin premiers seemed silly and pointless to me, but I stumbled into yours (for this video) and I must admit it was awesome seeing you there in the chatroom while you also talked us through in your video... it's like you finally hired an assistant. = )
@teemuleppa3347
@teemuleppa3347 5 жыл бұрын
silly question but how do i get to see that?
@anotherplatypus
@anotherplatypus 5 жыл бұрын
​@@teemuleppa3347 There's notifications that a that a premier video is scheduled in advance if you want to watch it live. For not-live ones you just gotta noodle around the video's page until you find the Replay Chat button. It even scrolls the chat history while you're playing the video.
@thijsdevries9016
@thijsdevries9016 5 жыл бұрын
Great stuff, as always!
@captainufo4587
@captainufo4587 2 жыл бұрын
The main reason/situation when I use HasSet instead of List is when i need to frequently check what's inside it. List.Contains() is an O(n) operation (that is, it takes longer the more stuff there is in the list), while HashSet.Contains is O(1), so it's constant speed no matter what. Dictionary.ContainsKey() is O(1) as well, but if you don't need to pair keys and values it's needless hassle.
@androxz7
@androxz7 4 жыл бұрын
Ive been a self though developer for more than 5 years... until this this day I had no idea what a hash set was... allways checking list to see if an item with a custom id was already there... oh silly me.... so yeah, thank you a lot.
@florinpricopie9112
@florinpricopie9112 5 жыл бұрын
Good job! Keep posting.
@MTandi
@MTandi 5 жыл бұрын
Thanks for sharing. But I didn't quite get the use case for the temporary stack of items. Usually you just won't allow addition of new items to a full inventory instead of keeping them in a temporary place that you have to make a UI for.
@dfhdgsdcrthfjghktygerte
@dfhdgsdcrthfjghktygerte 5 жыл бұрын
It is useful if inventory is meant to hold stackable items. Inscope studios on youtube made set of tutorials on system like that with good explanation why.
@MTandi
@MTandi 5 жыл бұрын
@@dfhdgsdcrthfjghktygerte I'm not sure that I was clear enough. I'm talking about the "_overflowItems" collection. If this is a collection of items that didn't get into the actual inventory, where would they go in real scenario?
@dfhdgsdcrthfjghktygerte
@dfhdgsdcrthfjghktygerte 5 жыл бұрын
@@MTandi I don't want to bring extra confusion, i just briefly looked into his code but to me it seems the purpose of _overflowItems is not to keep extra items, but add the ability to pop 1 item and push another one in it's place in case collection is full. And it looks like the popped item is removed in the process but it can be put into different slot, bag, inventory page for example.
@Unity3dCollege
@Unity3dCollege 5 жыл бұрын
It's a system we have in pantheonmmo.com where extra items you get from quests/etc that are force added to your inventory go into an overflow, then when you free a slot you can put it in your actual inventory. The goal is to allow people to finish quests/etc and still get the items without having to clear a spot in the inventory or stop the progression until they do :)
@martingrof1685
@martingrof1685 5 жыл бұрын
Your channel will grow if you keep up the excellent work!
@parthpandya008
@parthpandya008 5 жыл бұрын
Good stuff. Stack we can use for the Back Button functionality. Interested into see some info on Link Extension method and Link Statements
@alexanderlogunov5147
@alexanderlogunov5147 5 жыл бұрын
Awesome, thank you for the lecture
@rickloyd8208
@rickloyd8208 5 жыл бұрын
Thanks for awesome practical video tutorial. I noticed that in editor you have hints like "2 usages", "frequently called" etc What's that and how do you get them displayed? Thanks and like p.s. I also like how you hide setter of instance property, nice touch! p.p.s. Whenever you use fade out effect, I am thinking that my iPad went to sleep due to long inactivity :D
@derilas
@derilas 5 жыл бұрын
Nice video! Keep a good work!
@TheVagueIdeas
@TheVagueIdeas 5 жыл бұрын
super helpful, thanks!
@MathsPlusGames
@MathsPlusGames 5 жыл бұрын
Your the best
@timgheys
@timgheys 5 жыл бұрын
Slightly more advanced, but k-d trees are also interesting ...
@КонстантинЛактионов-щ1ю
@КонстантинЛактионов-щ1ю 3 жыл бұрын
I want create vocabulary game for teach languages. For me best collections for words is dictionaries ?
@Speiger
@Speiger 5 жыл бұрын
A good beginner tutorial. But there are some missing elements from the info you provided and that keeps it at a beginner level. (Just trying to provide constructive criticism) What you may or may have not known: Lists are just fancy arrays. And for your inventory system it would have been better because dictionaries have a cost to calculate the hashcode of an object. Which isn't even relyable unless you implement it yourself or don't create duplicates. For inventory the tldr is keep an array. HashSets & Dictionaries (or hashmaps) use hashcodes to define the uniqueness with a checkup for doublechecking. Also when iterated over it the output is semi random (foreach) because its based on how the hashcodes got sorted. Also in you lose performance because you iterate over every entry even if that is not present. There are faster options for hashsets/maps that are linked that give greater iteration performance but they are not by default in c#. Also there are two types of queue. A stack that is first insert & last extract. Or a linked list which is first insert & first extract. Also sorted queues like treesets or priority queues that can sort the values based on a comparator. Also what you may should suggest later too is to mix them up because loads of developers in unity I have seen decide to use only 1. You kinda did that with your dictionary stack but still wanted to tell how important that is. Thanks for providing a good beginner level tutorial because they are not as present. ^^ I hope this does not sound as yelling because I just wanted to provide Info's that back then I wished I had known.
@aliali-wb2gt
@aliali-wb2gt 3 жыл бұрын
plz make a c# game development toturial
@phillclough1656
@phillclough1656 5 жыл бұрын
How would I save the dictionaries to xml or any other way of parsing?
@Gonzakoable
@Gonzakoable 5 жыл бұрын
Yeah, I knew about these beforehand but I normally just default to lists/arrays because of the ease of use.
@robosergTV
@robosergTV 4 жыл бұрын
how is that a singleton if you dont check for other instances before assigning "this"
@fastbyte2235
@fastbyte2235 4 жыл бұрын
Maybe I am wrong, but if you are sure that this is going to be the only instance of this class and there is only one scene you can do that this way.
@robosergTV
@robosergTV 4 жыл бұрын
@@fastbyte2235 its not a singleton pattern then, a singleton is checking to be sure its the only one
@venenifer3569
@venenifer3569 4 жыл бұрын
People just got used to call any static field/property that returns an instance of that object a singleton, but if you don't check/destroy duplicates it really isn't a true singleton. But still, most people don't like the if (instance != this) { Destroy(this) } pattern because you lose control of what's being destroyed unless you are careful. But of course, if you don't trust yourself or your team to be careful with it you just shouldn't mess with the destroy singleton pattern at all
@yerasisaiprasadreddy
@yerasisaiprasadreddy 5 жыл бұрын
Please use dark theme in IDE
@BobrLovr
@BobrLovr 4 жыл бұрын
ew, no thanks. Dark theme is brutal on the eye strain.
@StygianStyle
@StygianStyle 2 жыл бұрын
@@BobrLovr The whole point of dark theme is to reduce eye strain. Looking at a bright screen is bad for your eyes.
@bharat2277
@bharat2277 4 жыл бұрын
Thank you
@НикитаЗеленцов-б1й
@НикитаЗеленцов-б1й 5 жыл бұрын
Thanks!
@justinwhite2725
@justinwhite2725 5 жыл бұрын
I’m the guy that uses arraylists far too often. I like dictionaries and queue though too. I think after watching this most of the places I use arraylists I might use hashmaps just because o check for redundancies far too often.
@sebastianwardana1527
@sebastianwardana1527 5 жыл бұрын
When you used the dictionary as an example, in the method LoadItems(), in the head of ToDictionary(key and value) the variables before the arrow, =>, are defined nowhere locally nor as class variables, does that mean key and value can be used after the method call of ToDictionary, or does it have something to do with ToDictionary?
@ritergart
@ritergart 5 жыл бұрын
So, just a question (it's not related to this video tho), the underscore for private parameters is recommended? Because I saw in a different video you uploaded, you mention to ditch the underscore. Great video tho!
@NickyDekker89
@NickyDekker89 4 жыл бұрын
1000th like! whoop whoop
@nosirrahx
@nosirrahx 5 жыл бұрын
Just got into C# and Unity, almost instantly moved from arrays to lists.
@pokoro97
@pokoro97 5 жыл бұрын
Too bad most of these don't get serialised by unity
@nadavrot
@nadavrot 5 жыл бұрын
Honest suggestion for your future videos - please stop shouting into your mic. It is VERY hard to go along when you are being this aggressive.
@myavatargotsnowedon9156
@myavatargotsnowedon9156 5 жыл бұрын
He's not shouting. The mic is pretty bad and peaking at the mids so when he does raise his voice slightly it clips which causes the crackling.
@47Mortuus
@47Mortuus 5 жыл бұрын
Out of actual curiosity: You wouldn't EVER create a method that is called "AddEnemy" which contains a single method call, which incidentally is called by "_enemies.Add()", would you? For me, THAT's the definition of spaghetti code - dogmatically "making things more readable" (except in this case LMFAO) by trading in tons of performance when all of these "simplifications" are added up. Same thing goes for creating a reference to a reference (initializing a variable) just to use it in some conditional statement, apparently for readability. I don't get it. Am I too intelligent? :D WhY dO pEoPlE dO tHiS?
@amirnurlanov4499
@amirnurlanov4499 5 жыл бұрын
Well, I don't really know how Unity or C# handles references(in terms of memory leaks) but creating a key, value pair(if that's what you're referring to) in any language is a given and the key not being a primitive is okay. The performance of retrieving items does depend on how the search algorithm is implemented for the key's type, though.
10 Steps I use to Design and Code Big Game Systems in Unity3D
30:14
Jason Weimann (GameDev)
Рет қаралды 70 М.
Code Smells - 'Switches' in Unity3d / C# Architecture
25:21
Jason Weimann (GameDev)
Рет қаралды 78 М.
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 42 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
37:51
bayGUYS
Рет қаралды 1,7 МЛН
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 757 М.
10 Things You Should Know in Unity
16:02
Jason Weimann (GameDev)
Рет қаралды 95 М.
Object Pooling (in depth) - Game Programming Patterns in Unity & C#
29:56
Jason Weimann (GameDev)
Рет қаралды 60 М.
I Made a 32-bit Computer Inside Terraria
15:26
From Scratch
Рет қаралды 4,1 МЛН
How To PLAN your Game as a Solo Developer
16:26
Heartbeast
Рет қаралды 525 М.
Events or UnityEvents?????????
15:43
Jason Weimann (GameDev)
Рет қаралды 105 М.
C++ vs Rust: which is faster?
21:15
fasterthanlime
Рет қаралды 407 М.
The Only Unbreakable Law
53:25
Molly Rocket
Рет қаралды 341 М.
The 6 Design Patterns game devs need?
24:20
Jason Weimann (GameDev)
Рет қаралды 374 М.