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

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ธ.ค. 2024

ความคิดเห็น • 80

  • @aronlinde1723
    @aronlinde1723 5 ปีที่แล้ว +29

    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.

  • @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.

  • @Unity3dCollege
    @Unity3dCollege  5 ปีที่แล้ว +26

    Fixed the audio, thx josh for fixing it and everyone else for calling it out :)

    • @ggjosh3296
      @ggjosh3296 5 ปีที่แล้ว +2

      Unity3d College anytime!

    • @VaporTrap
      @VaporTrap 5 ปีที่แล้ว +2

      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

  • @Alluvian567
    @Alluvian567 5 ปีที่แล้ว +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.

  • @stefano4993
    @stefano4993 5 ปีที่แล้ว +4

    I followed your instructions... my mom just published her first game!

  • @doudar41
    @doudar41 2 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

    Jason you have THE BEST unity tutorial content on the internet

  • @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.

  • @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!

  • @ShackMan
    @ShackMan 5 ปีที่แล้ว +2

    Another very useful video! I think it's great that you prepare everything and don't waste time typing line by line.

  • @rickloyd8208
    @rickloyd8208 5 ปีที่แล้ว +16

    Ideas for future episodes: serialization (lists and dictionaries) and coordinates (world, local, calculations and conversion of mouse pointer)

  • @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].

  • @DB-pt6zj
    @DB-pt6zj 5 ปีที่แล้ว +43

    Man I accidentally had playback at .75 speed. I thought you were drunk AF.

  • @andyBorko
    @andyBorko 2 ปีที่แล้ว

    Awesome! The best explanation of using collections! Thanks!

  • @peterquill726
    @peterquill726 5 ปีที่แล้ว +5

    Hashset is actually what I need in my project lol, why havn't I heard of it before is beyond me.

  • @simoncodrington
    @simoncodrington 4 ปีที่แล้ว

    Great video mate, nice simple use case for how to use hash sets. Cheers

  • @tonychristney2728
    @tonychristney2728 4 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      Glad to hear it was helpful. Collections are huge and really confused me for the first couple years. :)

  • @jugibur2117
    @jugibur2117 3 ปีที่แล้ว

    Very helpful, as always. Thanks Jason!

  • @DaniArkadia
    @DaniArkadia 4 ปีที่แล้ว

    Super useful stuff, thanks Jason.

  • @anotherplatypus
    @anotherplatypus 5 ปีที่แล้ว

    Initially the idea of TH-cam 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 ปีที่แล้ว +1

      silly question but how do i get to see that?

    • @anotherplatypus
      @anotherplatypus 5 ปีที่แล้ว +1

      ​@@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.

  • @diliupg
    @diliupg 5 ปีที่แล้ว +3

    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.

  • @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.

  • @martingrof1685
    @martingrof1685 5 ปีที่แล้ว +1

    Your channel will grow if you keep up the excellent work!

  • @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.

  • @ahmedthebest
    @ahmedthebest 5 ปีที่แล้ว +7

    Thank you for fixing the audio please use a dark script editor I can see the code

  • @thijsdevries9016
    @thijsdevries9016 5 ปีที่แล้ว +2

    Great stuff, as always!

  • @MTandi
    @MTandi 5 ปีที่แล้ว +2

    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 ปีที่แล้ว +2

      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 :)

  • @florinpricopie9112
    @florinpricopie9112 5 ปีที่แล้ว +2

    Good job! Keep posting.

  • @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

  • @rickloyd8208
    @rickloyd8208 5 ปีที่แล้ว +1

    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!

  • @alexanderlogunov5147
    @alexanderlogunov5147 5 ปีที่แล้ว +1

    Awesome, thank you for the lecture

  • @Speiger
    @Speiger 5 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

    plz make a c# game development toturial

  • @TheVagueIdeas
    @TheVagueIdeas 5 ปีที่แล้ว +1

    super helpful, thanks!

  • @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

  • @КонстантинЛактионов-щ1ю
    @КонстантинЛактионов-щ1ю 3 ปีที่แล้ว

    I want create vocabulary game for teach languages. For me best collections for words is dictionaries ?

  • @timgheys
    @timgheys 5 ปีที่แล้ว +3

    Slightly more advanced, but k-d trees are also interesting ...

  • @phillclough1656
    @phillclough1656 5 ปีที่แล้ว

    How would I save the dictionaries to xml or any other way of parsing?

  • @MathsPlusGames
    @MathsPlusGames 5 ปีที่แล้ว +1

    Your the best

  • @Gonzakoable
    @Gonzakoable 5 ปีที่แล้ว

    Yeah, I knew about these beforehand but I normally just default to lists/arrays because of the ease of use.

  • @bharat2277
    @bharat2277 4 ปีที่แล้ว

    Thank you

  • @yerasisaiprasadreddy
    @yerasisaiprasadreddy 5 ปีที่แล้ว +4

    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.

  • @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.

  • @НикитаЗеленцов-б1й
    @НикитаЗеленцов-б1й 5 ปีที่แล้ว

    Thanks!

  • @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!

  • @nosirrahx
    @nosirrahx 5 ปีที่แล้ว

    Just got into C# and Unity, almost instantly moved from arrays to lists.

  • @NickyDekker89
    @NickyDekker89 4 ปีที่แล้ว

    1000th like! whoop whoop

  • @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 ปีที่แล้ว +1

    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.