Data Structures For Game Devs: Arrays vs. Lists | Unity Tutorial (Part 1)

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

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

  • @AnnisVeryGoodGames
    @AnnisVeryGoodGames  3 ปีที่แล้ว +6

    Next part on HashSets! th-cam.com/video/qnLQTEqsXsk/w-d-xo.html

  • @vergilrose851
    @vergilrose851 หลายเดือนก่อน

    3 Years late but this helped me alot, thank you, very easy to understand

  • @Pontypants
    @Pontypants 3 ปีที่แล้ว +21

    Awesome series! :) Great for people like me who code as follows: ctrl+c, ctrl+v

    • @AnnisVeryGoodGames
      @AnnisVeryGoodGames  3 ปีที่แล้ว +2

      Thanks Ponty! :) I guess we're all living that pro coder life, no compromises!!

  • @ari12373
    @ari12373 7 หลายเดือนก่อน

    Very good video, the rookie programmer feels that he has learned very much, thank you for sharing and giving your time!

  • @tPlayerioT
    @tPlayerioT ปีที่แล้ว

    i like how you skipped the cientific part (0:50) to tell us in a better way with visuals, very nice video!

  • @SomeKrnDude
    @SomeKrnDude ปีที่แล้ว

    As somebody with very little coding experience, this guide made it really easy to digest the definitions and usages. Thank you so much!

  • @stellarr1
    @stellarr1 9 หลายเดือนก่อน

    Love the Dark Souls references ;)

  • @kayPlayz.
    @kayPlayz. 2 ปีที่แล้ว

    happy to come on your channel

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

    This is an excellent video for beginners in data structures. Thank you very much for making it. A year is too late for praise but have a heap of it anyway.

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

      I'll take it anytime, thanks! :D Glad it helped you out.

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

    gosh this is an amazing tutorial, thank you so much for making this!

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

    Wow, this is the best tutorial I have seen in this topic! Thank you so much!

  • @paypercutts
    @paypercutts 3 ปีที่แล้ว +2

    Nice and helpful for my own endeavors. Thank you. Also, very smart creating content to educate, which brings lots of new traffic and also incorporate your own game in there too. Keen for more!

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

      Great to hear! Yep, I didn’t really find a series like this, so why not try something new and make one! :)

  • @NamidaSai
    @NamidaSai 3 ปีที่แล้ว +2

    Great masterclass, you’ve got the perfect mix of edutainment going here. Good work!

  •  2 ปีที่แล้ว

    Thanks for the tutorial Anni!

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

    Thanks for the awesome series Anni. U got a subscriber. 😀👍🏻

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

    thanks for simple explaining i think we need more of these :D

  • @danielgalli6760
    @danielgalli6760 3 ปีที่แล้ว +1

    exactly what i was looking for thanks!!

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

    Brilliantly explained! I rarely find myself using arrays these days

    • @AnnisVeryGoodGames
      @AnnisVeryGoodGames  3 ปีที่แล้ว +1

      Thanks! Yes, chances are we're just wasting our time on unnecessary optimizations... ;P

  • @David18basso
    @David18basso ปีที่แล้ว

    Thank you for the class.

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

    Amazing stuff Anni!

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

    Hey Anni, nice video, thanks for sharing. I want to know how can i get the layer order value of the last element in a List ? Thanks 😊

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

    Yo you are great teacher. But I'm little dumb for programming. Great video. 👍

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

    Thank you! Very understandable and entertaining!

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

    Nicely presented 👍

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

    Love your video awesome content;!

  • @WhiteNorthStar1
    @WhiteNorthStar1 ปีที่แล้ว

    LOL... so useful (and funny!)

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

    Hello .. from now i will follow your video because it is awesome
    Love from India🇮🇳🇮🇳

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

    @0:48 I actually kind of like the idea of an autobook for computer books. Then again I'm a nerd who dislikes reading.

  • @kayPlayz.
    @kayPlayz. 2 ปีที่แล้ว

    i need help ,
    i have a situation that i am creating different lvls in same scene, that is i disable lvl 1 object from the hierarchy and enable in same position second lvl, and player after player collide with finish line it came back to starting position in lvl 2 .
    but i cant disable and enable objects after collison except 2 lvls
    and 3 lvl is not opening , i tired with loop and arrays but not working.

  • @SGUDevs
    @SGUDevs 9 หลายเดือนก่อน

    which method can allow you to create categorization and be customizable?

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

    could someone explain this to me regarding Arrays:
    if we are making an array of type int, which is called highscores, why dont we start listing the content of the array after the "="?
    what's the point of writing "int[] highscores = new int[3]"? Are we making a new array?
    Can't we just do "int[] highscores = 3,5,7"?

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

      In C# we have to write new keyword to declare an array.

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

    hey htere how to use list , gameobect list of any type which derivates from an abstrac class? is it possible.

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

      Yes, if you want a list of GameObjects:
      List goList;
      Or if you want a list of items that all derive from the same (abstract) base class:
      List anotherList;

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

    Posting my comment here because you only make mention of it here, and not in the Dictionary Video.
    At the 35 sec mark, you have stated that a Dictionary lookup is O(1), which is farthest from the truth that you think. Under the hood, a dictionary uses a for loop and other things to look this key up. The fact that it loops over the dictionary data, makes it an O(n) lookup.
    And FYI, if you actually do a two-dimensional array with the first being the key and the second being the value, and do a for loop over both arrays. To get to the last item in both scenarios, the two dimensional Array is faster by a significant amount than what a dictionary is to get the last item out of the dictionary.
    Sorry, as much as I love your videos, this small bit of information is important!

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

      Hi! Thanks for your comment! However, you're wrong. :)
      A dictionary lookup is not O(n). For a lookup, a hash code is computed from the lookup key using a so-called hash function. The resulting hash represents the address of the Dictionary entry, so no looping is required. I have a suspicion that you may have looked at the internal implementation (which is a great idea in general!) but are confusing something. As you can see, a loop is still necessary. However, it loops over all the items in the _bucket_ (not in the Dict overall!) that the computed hash points to. Such a bucket may contain multiple Dictionary entries in case of hash collisions. A hash collision occurs when multiple Dictionary keys result in the same hash code when used as input for the hash function. A decent Dictionary implementation will try to minimize such hash collisions (it's a space vs. runtime tradeoff), avoiding buckets that hold many entries. By the way, this is also why there is no "last item" in a Dictionary; it is not an ordered data structure.
      Another option is that you're misunderstanding Big-O notation: A loop does not automatically make something a linear-time O(n) computation. The runtime of the for loop has to increase linearly with the number of items in the data structure, which is not the case in the C# Dictionary implementation.
      Also check out the Microsoft documentation for Dictionary lookups. It says: "This method approaches an O(1) operation."
      That said, in some scenarios, arrays or lists MAY still provide faster real world lookup speeds than Dictionaries or HashSets. There are many determining parameters: Size of your collection, access patterns in code, your hardware (cache size), effects from cache locality, computation speed of the hash function, etc. (I think I mention this somewhere in Part 4 of the series.)
      If you truly need to optimize runtimes at this level of your code, the best way to go about it is typically to run benchmarks for your exact use case. Performance optimization is hard.
      Lastly, while a two-dimensional array may work as you suggest (I haven't checked), I believe it's typically going to be a bad idea to prefer such a home-baked construct over library data structures, especially for beginners, who this video series is directed at. I mention the reasons somewhere in the videos: better readability, fewer bugs, more time to spend on what you're actually trying to do, and, importantly, a beginner likely (and luckily, haha) has absolutely no need to optimize at this level (yet).
      Phew, long response. Happy new year and let me know if I missed something!

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

      @@AnnisVeryGoodGames Then I suggest you time it, and grab a value from various positions and see what the difference is. If it is O(1) the time it takes to grab the value based on the ky should be the same.
      Or, you simply could go to the source code for a Dictionary and see exactly where they do a for loop to grab the value based on a key! That by definition makes it O(n)

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

    is eny Data Structures that contain more the one verble for each off the elements the have
    im tried to create an inventory system and I want data for each off my elements
    for example if use array or list the contains only one type off elements for each type for example i array with game objects
    each off my Data Structures need to have more the one Data for example to include name off the ,item, text,icon etc
    otherwise if ther is no way to do that i will need to follow one off thos method
    1. use the same code multiple times that contained all the verbles in public
    2. use 2 array or more and to makes sure that in the code the Mach both element for both arrays
    that both of those methods is kind off tedious

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

      Check out my video on dictionaries, it's part 3 of this series and should have what you need. :)

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

    How to access list in another Script and store it? Like,
    If I store Transforms of houses in list in one script. And other script, i want to access only one house in that list and store it transform to new variable in this script

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

      The best way to do it might depend on your exact use case, but if the script with the list is attached to a game object called "go", and if the class in that script is called "HouseList", to access the list "houseTransforms" within: go.GetComponent().houseTransforms;
      Good luck!