Introduction to Game Development (E17: reference vs value types)

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ม.ค. 2025

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

  • @junpeiiori4720
    @junpeiiori4720 7 ปีที่แล้ว +114

    You should be awarded for these concise yet really helpful masterclasses!

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

      Agreed. These are far more clear than many of the official Unity videos.

  • @pranav_r
    @pranav_r 7 ปีที่แล้ว +130

    Well, there you go. 1 1/2 years of computer science before this was cleared up.

  • @icedragongamemaster6797
    @icedragongamemaster6797 6 ปีที่แล้ว +16

    I was reading about this for a year and didn't understand it well. With your 7 min tutorial you gave me much better understanding. Thank you very much Sebastian Lague.

  • @ayyildiz-ccc
    @ayyildiz-ccc 4 ปีที่แล้ว +10

    It's 2020 and these videos are very useful to start with Unity.

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

    Thank you so much for making these videos. As someone just learning game development focusing on programming, there is a lot of simplistic and outdated stuff out there that wastes your time. I don't need a step-by-step tutorial on how to make a dinky little game no one will care about - I need to know how to *think* about this stuff, how to *approach* it in a more general sense. Can't wait to get through the rest of the series.

  • @intuithue
    @intuithue 6 ปีที่แล้ว +35

    oof i am feeling confused about this one, but it's the kind of confusion where it feels like being confused is doing something- it just needs time to gather and i need to find some more examples. thank you for these lovely, extremely well-made videos!

  • @iviecarp
    @iviecarp 4 ปีที่แล้ว +2

    I already knew this stuff but once again I have to praise the clarity of the explanation, much like your neural network video. This makes it crystal clear and if I need to explain this to anyone, I have somewhere to point them to now, thanks

  • @NaughtyDuck
    @NaughtyDuck 7 ปีที่แล้ว +41

    FINALLY. THANK YOU JESUS! i mean THANK YOU SEBASTIAN!

    • @skgames1581
      @skgames1581 7 ปีที่แล้ว +3

      Mr Fox OMG YESSSS!!!

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

    I don't know if you still read these comments but this series is insanly good. Thank you very much :)

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

    Your each and every word is golden in this video!. Couldn't be explained any better than this.

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

    Found this out the hard way whilst writing trying to manipulate lists in python a few years back. Thanks for this.

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

    Amazing stuff! Finally all my programming doubts are cleared. Thank you so much!

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

    I managed to solve an issue I was having (unless I later find an issue with it) using knowledge of how reference/value types work from this video, so thanks for giving a proper understanding of what these types are.

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

    2:10 interesting note to take: if you will test the following:
    (a.x == b.x)
    (a.y == b.y)
    these will both be true :) while a ≠ b

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

      Because x and y are value types and their equality depends on the value itself not the reference

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

    Faz apenas 3 dias que estou assistindo esse cara e já quero assinar o patreon dele, mds, que homem

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

    oh gosh, that helped me a lot & saved may hours of confusion! Thanks!

  • @Gregasaurus
    @Gregasaurus 6 ปีที่แล้ว +2

    holy f*ck that's clarity. thank you baby jesus for your videos

  • @HairyPixels
    @HairyPixels 7 ปีที่แล้ว +2

    Is there no distinction between the stack and heap in C#? As far as performance is concerned there's something to be said about optimizations that can be made by allocating memory either on the stack or heap, which is very relevant to game programing.

  • @EntropicalNature
    @EntropicalNature 7 ปีที่แล้ว +1

    Superb explanation, as always!

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

    That's great, Structs have been confusing me and this cleared things up for me quite a bit.

  • @videosyoutube718
    @videosyoutube718 7 ปีที่แล้ว +1

    Dude, incredible video, and worth for more than games, thx you so much!!

  • @redenvalerio601
    @redenvalerio601 6 ปีที่แล้ว +1

    Best tutorial about basics of unity. really recommend watching all his videos.

  • @ewwitsantonio
    @ewwitsantonio 7 ปีที่แล้ว +1

    Excellent video. Thanks, Sebastian!

  • @patentleatherkicks
    @patentleatherkicks 7 ปีที่แล้ว

    Thank you! In your next Intro to Game Dev episode, please consider covering Properties and Accessors

  • @FacePalmProduxtnsFPP
    @FacePalmProduxtnsFPP 7 ปีที่แล้ว +1

    VERY good visualizations. Ty so much!

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

    For resource management, would it be effective in the case of this example, to check if a point has the exact same values and rather than create a new point with the same values, reference the point that has the desired values? Or would the performance loss of looking for a point stored with that value outweigh any possible gains? All of this is assuming that all points values will remain constant and never change.
    I've been programming for several years self taught with Lua and now learning C# has introduced me to some seriously different standards. You're videos have been a great asset to me.
    I realize these videos are fairly old, however I was also wondering, if you are still creating content, if you would do an in-depth review on programming shaders in unity? I know we have a shader graph now, but the code actually seems easier to understand for me.

  • @r3s3tme
    @r3s3tme 7 ปีที่แล้ว +1

    good stuff, is there any tutorial explaining the = ~ or = ( x

  • @TeamHarrisonMachine
    @TeamHarrisonMachine 7 ปีที่แล้ว +2

    VERY USEFUL TUTORIAL! Thanks! I've been trying to understand what struts are and the difference between reference and value types for the longest. One question though... how are constructors different from structs?

    • @SebastianLague
      @SebastianLague  7 ปีที่แล้ว +6

      A constructor is just a way of setting the values inside a struct or a class when a new object is created. So constructors aren't "different" from structs, they're a part of structs (as well as classes).

    • @TeamHarrisonMachine
      @TeamHarrisonMachine 7 ปีที่แล้ว

      Thanks!! You're the best!

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

    Hey Sebastian, so Point a = new Point (2, 5) creates a new object in ram.
    Then what happens if I do a = new Point (2,5) again?
    The previous object in ram is till in there?
    Like, if I do a = newPoint (2,5) like 100 times, will 99 objects of Point be kept in ram without being used? Is that an issue?

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

    If we have out, why do we need ref?

  • @saeklin
    @saeklin 7 ปีที่แล้ว +1

    Whoa, so THAT'S what structs are for! Thanks. Maybe you should have mentioned pass by value though.

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

    The problem I have is knowing how unity declares it as struct or class. Transform could be used as a struct more than a class for me at least but its a class in unity. I think C++ pointers make it more clear in terms of whats being referenced and whats being copied

  • @darwinwillers6909
    @darwinwillers6909 7 ปีที่แล้ว

    Awesome Video you should make a series out of this.

    • @VBKing2
      @VBKing2 7 ปีที่แล้ว +6

      Darwin Willers great idea. Then he could do reference vs value types in...
      EPISODE 17.

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

    Hi Sebastian,
    Wanna add that list elements and array elements behave as reference types when stored in structs however list and array itself behaves as value type like i can modify any element of array/list stored in struct but could not replace the whole array list/array.
    someStructObject.array = new int[]{1, 2, 3}//this does not have any effect on someStructObject;
    someStructObject.array[0] = 5;//this updates the first element of someStructObject array to 5.
    Read the comments in code.
    public class Test : MonoBehaviour
    {
    void Start()
    {
    MeshTris m = new MeshTris(new int[] { 1, 2, 3 });
    RunTest(m);
    // Here m is modified and new values of m are 4, 2, 3
    }
    void RunTest(MeshTris meshTris)
    {
    meshTris.tris[0] = 4;;
    }
    }
    public struct MeshTris
    {
    public int[] tris;
    public MeshTris(int[] tris)
    {
    this.tris = tris;
    }
    }

  • @linuxguy1199
    @linuxguy1199 7 ปีที่แล้ว

    Java needs structs, also, amazing tutorial

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

    This is why I really wish more high-level languages did references under the same sort of semantics and syntax as pointers in C.
    The problem with making reference semantics so implicit is the fact it's so stupidly easy to introduce bugs into code because the language is all too happy to make things a reference and not tell the programmer.
    In my opinion a well-designed language will always default to values and never ever implicitly switch to reference semantics without the programmer explicitly invoking them.
    This is why C succeeds in so many places C# fails.
    For example, in C# you can do Point p = new Point(5, 10); and C# will do it without complaint.
    In C++, you'd get an error because you're trying to instantiate an object on the heap and then assign its address to something that is NOT a pointer. The compiler would reject the code and tell you this.
    It should be Point *p = new Point(5, 10); The * there makes it clear in the code that you're working with a pointer. The programmer EXPLICITLY invokes something like a reference instead of the language sneakily invoking a reference on the programmer behind their back.
    Yes, pointers can be confusing, but they're probably the source of a LOT less hard-to-find bugs than implicit references.
    And yes, C++ does actually have a non-pointer reference semantic, but AGAIN, it requires that the programmer explicitly invokes them, and when the actual reference itself is used, the effects fall back to acting like you're acting by value. You pass things by reference into a function in C++, but you're not stuck dereferencing anything to work with it, and when you actually assign from something passed by reference, you're still invoking the expected copy semantics.
    It does have the side effect of introducing side-effects, though, since passing by reference means you're not working with a copy of an object when you pass it into a function, so if you change the object passed by reference in a function it'll be changed in the caller function as well, which is why in C++ you'll most frequently see references being passed into functions as const, so that the object cannot be changed by the called function.
    But, as much as I like Python and work with it, I'm not a fan of languages that assume it's safe to go into reference semantics without the programmer making that clear on their own. It's weird to me classes and structs are supposed to be the distinguishing factor in C#.

  • @victornaut
    @victornaut 7 ปีที่แล้ว

    You definitely should consider making Monogame series... tutoring can't be any neater than this.

  • @HowToMakeMobileGames
    @HowToMakeMobileGames 6 ปีที่แล้ว

    Very useful, thanks :)

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

    If reference types can't be equal to each other without referencing the same point in ram, how come you can check if Vector3s are equal to each other?

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

      Vector3s are value types not reference types, so it just checks if xyz are the same for both

  • @DavidZobristGames
    @DavidZobristGames 7 ปีที่แล้ว +1

    thank you that was epic

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

    For anybody: What's a quick example of what one could use structs for? I've never personally had to use one and, judging by the way they behave, I wouldn't necessarily want to use one for fear of losing track of what a variable is supposed to be doing.

    • @mhhm-mq3ct
      @mhhm-mq3ct 4 ปีที่แล้ว

      if you would watch carefully, he explained that almost all in-built types are structs ... if you ever use float, bool, then you have used structs.

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

      @@mhhm-mq3ct Fair enough. I guess I wasn't referring to those structs. I was more or less looking for examples in which one would go "Hey, I don't need a class right now/ a class is just too much/ doesn't suit the task at hand, I need a struct." Like, specifically, when you could use a class, why would one forego it for a struct instead? That's more or less what I was trying to ask. I probably wasn't being clear, I'm kind of new to all of this, but floats and bools and stuff kind of misses the point of the question I was trying to ask.
      "If you would watch carefully" Well, I did. Multiple times, in fact. So..
      .... Why the attitude sir? You initially come off to me as bitter. Why are you mad? I ask because you seem to assume I didn't watch this 5 times beginning to end already, and it kind of pisses me off you felt the need to begin your comment with this incorrect assumption that I didn't already watch this fully well before posting, or wasn't willing to "watch carefully".

  • @hatebagel9523
    @hatebagel9523 7 ปีที่แล้ว

    hi its me pie again. I imported the 3d model I made into unity and for some reason the colors only show up when I look at the model from underneath it or through the side of one of the bumps in the map. I imported the model in an fbx file and I was wondering if i was supposed to. is there a way for me to send you screenshots of the problem so you can see yourself? thank you

    • @IAdamEvansI
      @IAdamEvansI 7 ปีที่แล้ว +1

      Sounds like your normals are flipped. should be able to fix this fairly easily in whatever modelling software you are using.

    • @hatebagel9523
      @hatebagel9523 7 ปีที่แล้ว

      Zaphod BeebIebrox thanks but how do I flip the normals

    • @hatebagel9523
      @hatebagel9523 7 ปีที่แล้ว

      Zaphod BeebIebrox I'm using blender

    • @IAdamEvansI
      @IAdamEvansI 7 ปีที่แล้ว +1

      In blender I think it's just ctrl +N in edit mode, should recalculate normals.

    • @hatebagel9523
      @hatebagel9523 7 ปีที่แล้ว

      Zaphod BeebIebrox k

  • @TeamHarrisonMachine
    @TeamHarrisonMachine 7 ปีที่แล้ว

    Could you make a tutorial that explains what an uint32 is and why we would want to use it?

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

      Those are "custom" data types created by the IDE or API,.. on different Systems an int may use e.g. 4 Bytes (32Bit), 8 Bytes (64Bit) or only 2 Bytes. This is specific to the target system.
      By using uint32 your unsigned int will reliable use 4 Bytes

  • @homunduruk2530
    @homunduruk2530 7 ปีที่แล้ว

    I must say that before you I hated C#. Now I actually like it a little bit.

  • @bibib8583
    @bibib8583 7 ปีที่แล้ว +1

    THANK YOU!!!

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

    And why do both methods and structs have to exist? what are the pros of each over the other?It seems to me that structs make more sense. OOOOh, do structs not have parameters? And that's why we need methods as well?

  • @unessoum8335
    @unessoum8335 7 ปีที่แล้ว

    Thank you

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

    Cheers

  • @alix6477
    @alix6477 7 ปีที่แล้ว +4

    What my computer science is trying to learn us since 2 months lol.
    Thanks, i did'nt knew what object.method was meaning in visual studio.
    Fun fact: I have an exam on it today.
    Thanks!

    • @ChopChopMinecraft
      @ChopChopMinecraft 7 ปีที่แล้ว +12

      I hope it's not an English exam...

    • @UltraTonto
      @UltraTonto 6 ปีที่แล้ว

      @@ChopChopMinecraft lmao

    • @UltraTonto
      @UltraTonto 6 ปีที่แล้ว

      I mean, at least it is understandable.

  • @dreyx7058
    @dreyx7058 7 ปีที่แล้ว

    nice!

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

    7 minutes passed so quick

  • @sagarpatel1633
    @sagarpatel1633 7 ปีที่แล้ว

    Hey Sebastian Lague i am learning a lot from your video.Thank you very much
    Recently i completed you 2d platformer series.And I have also implemented climbing,swimming,shooting,pushing,dashing,player underairforce,jetpack,crouching and also enemy AI ,created an animator to handle all animation can i sell that asset on unity asset store for 5$ only with your permission

  • @Araraura1
    @Araraura1 6 ปีที่แล้ว +2

    Am I the only one confused by this?
    everyone here seem to understand this, but this is confusing af for me

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

      Could start by asking questions, nobody can help you if you don't state the problem

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

      @@Arbeta10000 Well his question was if there was other people confused by this, not a question with which answer he can help himself, but instead comfort himself that there are other people who are confused as well. So. just type "Omigod, yes, I am also confused", and that will help him a lot! lol...

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

      @@Ggd07 That's not a useful question to ask though, if they want comfort then the internet is the last place for them to go, because it's full of people who will do the opposite as well. xD
      I'm not one of those, mind, but the real question in Araraura's comment seemed to be "could somebody help me understand this?", at least from the way it's phrased.
      If you went up to a teacher and said "I'm confused by this" then it'd be a bit unnatural for the teacher to say "I'm not" or "me too". They'd assume that their sentence was meant as a question.

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

    this is free btw

  • @Gregasaurus
    @Gregasaurus 6 ปีที่แล้ว

    finally........

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

    im sorry sebastain but i dont really get any idea of what ur saying :( PS: Im 12

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

    Unfortunately this was the first video to completely lose me. It was WAY too abstract for me to follow. I struggle to follow things that aren't accompanied by something demonstrating *why* I would be using the demonstrated method. As in, an actual program (even if super simple) with a tangible task. Simply seeing all those letters didn't make a lick of sense to me :-/ heading into the next tutorial and hoping that's where it will all make sense.

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

    "Introduction" to Game Development