What are Value Types and Reference Types in C#? (Class vs Struct)

Поділитися
Вставка
  • Опубліковано 6 січ 2025

КОМЕНТАРІ • 128

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  5 років тому +16

    Did you know the differences between the types? How many times have they confused you?
    🎮 Play 7 Awesome Games (Action, Strategy, Management) and Help Support the Channel!
    ✅ Get the Game Bundle 67% off unitycodemonkey.com/gameBundle.php

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  5 років тому +51

    NOTE: Although string is a Reference Type, it behaves like a Value Type (immutable) When you assign a variable it receives a copy and not a pointer.

  • @mrmogelost6720
    @mrmogelost6720 3 роки тому +33

    Definetely the most underrated programming channel on the platform. Stunning content

  • @zacharytorr1472
    @zacharytorr1472 3 роки тому +4

    Countless hours wasted failing to debug and understand why my data was being changed, seemingly for no reason. Thank you so much.

  • @katifurkan
    @katifurkan 4 роки тому +1

    This video should be the first on the playlist. Just an advice.

  • @thedeltastrat
    @thedeltastrat Рік тому +2

    This is exactly what I needed! This problem had been vexing me for a while, thanks a bunch

  • @connormyers322
    @connormyers322 4 роки тому +6

    Thanks, I've been struggling to figure out how c# was structured, and how to manage instances, this helped a TON!

  • @JKhalaf
    @JKhalaf 2 роки тому +1

    This clarified the difference between value types and reference types really nicely, thank you.

  • @jean-michel.houbre
    @jean-michel.houbre 5 років тому +7

    Excellent video, which I wish I had when I started C #.
    Thank you for all these videos!
    (I bought Clean Code. I did not keep very good memories of my last big book in English, but this kind of book is rarely translated into French).

  • @sanc6284
    @sanc6284 4 роки тому +1

    THANK YOU!! I never understood why I had to keep declaring new whatever type until now.

  • @jtlewis81
    @jtlewis81 2 роки тому

    I just found this video useful as a reference for a college forum discussion. Thanks CodeMonkey!

  • @SkaiCloud562
    @SkaiCloud562 5 років тому +3

    You just taught me something today.

  • @vrtech473
    @vrtech473 5 років тому +2

    This is extremely useful! I was encountered this problem before and it is so frustrating

  • @siestitrokot3843
    @siestitrokot3843 3 роки тому

    Just want to say thank you. Great tutorial!

  • @neozoid7009
    @neozoid7009 2 роки тому

    awesome explanation CM love your videos . keep making more Awesome videos on C# unity like this

  • @williamiiifarquhar4345
    @williamiiifarquhar4345 3 роки тому

    Thank you for the explanation! You have some really high quality content.

  • @ANAND-zw1on
    @ANAND-zw1on 4 роки тому +1

    I learn many thing by this😀😀😀😀

  • @mr_noodler
    @mr_noodler Рік тому

    Value types are bytes of data that contain values in memory, reference types are addresses to bytes of data in memory. Reference types are pointers (C/C++) to an address, and variables/fields store data.

  • @gladiumcaeli
    @gladiumcaeli 5 років тому +1

    Thank you so much for making these tutorials :)

  • @daveB133
    @daveB133 4 роки тому

    Great vid, thank you. One improvement could be a little diagram which pops up which shows what's going on 'under the hood'. in relation to the reference pointers/value copies.

  • @track9891
    @track9891 10 місяців тому

    at last i understand 😁Thanks

  • @johnnythesilverhand
    @johnnythesilverhand 5 років тому +1

    awesome tut ;) please make tuts for design pattern in unity

  • @n0expressi0n16
    @n0expressi0n16 5 років тому +1

    wonderful, so beginner friendly

  • @zoobs-y2x
    @zoobs-y2x 4 роки тому +1

    love your videos you're great! keep making more!

  • @volkangundogdu1008
    @volkangundogdu1008 4 роки тому

    well done description, and statements congratulations

  • @cenkylmaz4294
    @cenkylmaz4294 3 роки тому

    Tahnks very helpful video!

  • @mr_noodler
    @mr_noodler Рік тому

    This is a good channel😊

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Рік тому +1

      I'm glad you found the video helpful!

    • @mr_noodler
      @mr_noodler Рік тому

      @@CodeMonkeyUnity yeah you bet good stuff

  • @FinitiXgameDepartment
    @FinitiXgameDepartment 4 роки тому +1

    perfectooo----trying to add some italian accent, but God knows i am from middle East.

  • @aaaalord
    @aaaalord 11 місяців тому

    Thank you Jacob ❤

  • @therunnerproject
    @therunnerproject 5 років тому +16

    Nullable enums are baaaaaaad practice, normaly you use "None" as the default value.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 років тому +6

      Yeah I agree that's normally what I do but I wanted to show that there is a way to make a value type null.

    • @therunnerproject
      @therunnerproject 5 років тому +2

      @@CodeMonkeyUnity The only good use case i can think of would be database in models like nullable DateTime.

  • @asmr_codster
    @asmr_codster 2 роки тому

    Cool video!

  • @Brian-nz6ns
    @Brian-nz6ns 2 роки тому

    @3:57 you changed the value of b to 5, so why does it equal 7 ? Does b=5 not make the variable equal 5 ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому

      It sets 'b' to 5 but ints are value types so the value stored in 'a' is still 7

    • @Brian-nz6ns
      @Brian-nz6ns 2 роки тому

      @@CodeMonkeyUnity Oh...the console showed the value of a, that's what I missed and couldn't understand why the answer was 5. You were talking about b so I thought that's what the console was showing the value of.

  • @axcpt9028
    @axcpt9028 5 років тому

    You are a legend bro

  • @antonai367
    @antonai367 5 років тому

    thank you for this tutorial

  • @mohamedessam-6228
    @mohamedessam-6228 5 років тому

    Great.
    Thanks alot. ❤️

  • @mydreamprojcts
    @mydreamprojcts 2 роки тому

    Hey Code Monkey...How the Data Stores of Variable and Reference??How the Code Run,Excute and Compiler in Unity ?? for example It get Convert into C++ and so on..So What will the Best Practises ??

  • @VeeZzz123
    @VeeZzz123 4 роки тому

    thank you very much

  • @anonymoussloth6687
    @anonymoussloth6687 3 роки тому

    When we assign things to variables in the inspector, we are assigning the reference for reference types? And copy of the value for the value types?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому

      If it's a transform or MonoBehaviour? Yes reference.
      But if you make a Class field then it will simply construct a class instance

    • @anonymoussloth6687
      @anonymoussloth6687 3 роки тому

      @@CodeMonkeyUnity I got the first part. But what do u mean by class field?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому

      @@anonymoussloth6687 if you define a class, like public class MyClass { }
      And you make a field of that type, it will construct an instance of that class

    • @anonymoussloth6687
      @anonymoussloth6687 3 роки тому

      @@CodeMonkeyUnity oh I see. So if there is a script on a gameonject that has the field of Myclass, and I drag the script Myclass.cs into it in the inspector, it will create a new instance of the class? And if it's a transform or mono behaviour, then it will have a reference to it? But what if there is a mono behaviour that isn't instantiated? In other words, I just have the script but it hasn't been put on a game object yet

  • @bigsmoke5746
    @bigsmoke5746 4 роки тому +3

    For anybody: What's an Intuitive example of when one would choose Structs over a Class? It woudnt ever occur to me to use a struct for anything that wasn't DOTS since I've never needed one in the past. Judging by the way they behave, I also wouldn't necessarily want to use one for fear of getting confused.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому +4

      The one main benefit is performance due to how structs are stored in the Stack rather than the Heap.
      For example if you have a massive array that you want to cycle through, it will be faster with Structs rather than Classes because of where they are stored in memory.
      This benefit exists even in non-DOTS code.
      For example in my game, Survivor Squad, I had a massive array to control the Fog of War, just a simple boolean saying hidden or visible. First I made it with classes and it was painfully slow, switched it to structs and everything worked perfect.
      But yes, in 95% of cases you should use Classes since they will be easier to work with and only use Structs if you absolutely need it.

    • @bigsmoke5746
      @bigsmoke5746 4 роки тому

      @@CodeMonkeyUnity Fair enough, thank you so much for your reply! I'll definitely keep that in mind about the array size.

    • @WagnerGFX
      @WagnerGFX 4 роки тому +3

      I had an issue in my project where the Garbage Collector was being called too often due to a routine running in the Update. When I changed a parameter's type from class to struct the issue practically disappeared since the struct was handled by the Stack.
      This might not give a massive performance boost, but many different platforms and PC specs handle GC differently which could create some issues, so it's good practice to avoid overworking the GC whenever possible.
      What I learned from this was: If you have some data that is short lived (inside a method) and sent around the code very often as parameters (like inside an Update) it could be better to use a value type to avoid GC overwork.
      Always Profile the project, if you see too many GC calls then changing the way you handle data from classes to structs or other value types might be a solution.

  • @tigerspidey123
    @tigerspidey123 2 роки тому

    From architectural memory point, I want to understand this correctly. Struct goes into Stack, while Class are allocated dynamically into heap? Also what if I apply a pointer to to a struct in unsafe code? what will happen then?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому

      Pointers go to the stack so in that case you would have a pointer on the stack pointing to a struct also on the stack

  • @aoiti
    @aoiti 3 роки тому

    The nullable structs are not shown in unity inspector. Is there a way to fix that?

  • @hawns3212
    @hawns3212 5 років тому +1

    Thanks.

  • @smitesoft6824
    @smitesoft6824 3 роки тому

    Just amazing

  • @Khantia
    @Khantia 2 роки тому

    I know that this is a fairly old video, but I do have a question:
    I have a class, which holds some nested structs within in. And sometimes I do want to pass down copies of the structs, but other times I wanna pass down a reference (as read only) for faster computation times. How can I do that?
    I mean... the example shown in the end doesn't really work for me, because what I'd wanna do would look something like this:
    MyStruct asd;
    public void SetUp(ref MyStruct dsa)
    {
    asd = dsa;
    }
    And this would just make a copy of dsa, wouldn't it? And writing "ref" before asd just gives me computational errors.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому

      What are you trying to do? If you need an object to behave like a class why not make it a class instead of trying to make a struct behave like a class?

    • @Khantia
      @Khantia 2 роки тому

      @@CodeMonkeyUnity I was considering that, but wanted to hear if there is a way to do it with a struct.
      However, how would this behave:
      public struct MyStruct
      {
      public float[] values;
      public MyClass cls;
      }
      public MyClass
      {
      public float[] moreValues;
      }
      Would passing by the struct around make copies of the class within it, or would it be a reference?
      As for what I'm trying to do: I'm making a game with selectable heroes/classes. And I am keeping the hero stats and abilities within a struct. And when a hero is selected, I copy the desired struct onto them, with the idea that changes can be made in the future, with talents and such, without affecting the other heroes who use the same class. And when casting a spell, I pass on the nested struct, with the spell data within it (such as damage, range, speed, etc) to the spell.

  • @Drifts3
    @Drifts3 5 років тому +1

    So is it always recommended to use classes over structs? Very informative video nevertheless, but it can be good to give examples of where the misuse or best use of the methods you describe ( beginner here ).

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 років тому +5

      Classes are easier to understand so for the most part that's what you should use. Structs are beneficial when performance is an issue even when not using Unity DOTS.
      However when working with Unity DOTS you don't have a choice, in order to benefit from all the massive performance boosts you have to use Structs.

  • @factopiavideos
    @factopiavideos 5 років тому +1

    Hey bortha, this might not be in your road map, but can you make a tutorial on how to make a 2d sprite into pieces on trigger. (we can later add point effector to blow it ). Thanks for all these tutorials man.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 років тому +1

      You mean cut up the mesh into a bunch of separate parts?

    • @factopiavideos
      @factopiavideos 5 років тому

      @@CodeMonkeyUnity Yeah but something in your way.

  • @marksmithcollins
    @marksmithcollins 5 років тому +1

    Nice video!
    So, string is not usable in DOTS component, is it? Is there any built-in container for storing text in Unity?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 років тому

      I don't think there's any built in container for strings, chances are whatever problem you're trying to solve doesn't really need strings.
      If you absolutely needed to use strings I guess you could use a NativeList and handle it character by character.

    • @marksmithcollins
      @marksmithcollins 5 років тому

      @@CodeMonkeyUnity How about NativeStringXX structs?
      docs.unity3d.com/Packages/com.unity.entities@0.0/api/Unity.Entities.NativeString64.html

  • @SenthilKumar-gz6rz
    @SenthilKumar-gz6rz 5 років тому

    Make these kinda video.cool. I want to know static and heap memory management. Anyhow video is nice

  • @danellboy5757
    @danellboy5757 3 роки тому

    This is really interesting. Could someone tell me a scenario where knowing this is useful? It would be interesting to hear it in real world context to help me understand it better. Any help's appreciated, thank you!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому +3

      The fact that structs/classes exist in different locations in memory (stack/heap) can be a huge difference in terms of performance.
      I remember a long time ago when I was working on Survivor Squad and I had the Field of View code and it was taking a massive amount of time every frame, once I switched it to structs instead of classes the performance increased massively.

    • @danellboy5757
      @danellboy5757 3 роки тому

      Oh fair, thank you code monkey!!!!

  • @anime4u568
    @anime4u568 5 років тому

    please sir Can you make a video on how to make a walk animation using code (your animation system) Thanks alot. your videos are really awsome and verry helpfull

  • @tiagodarkpeasant
    @tiagodarkpeasant 5 років тому

    what a coincidence, i had this question yesterday, i pass an List as a parameter, but the items added to the list don't go to the original list, and i always believed a list was a reference type

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 років тому +3

      List is a reference type and that should be working correctly so it sounds like you have a different issue. Maybe you're actually passing a copy?
      DoSomething(myList.ToList());
      This would pass a copy instead of the original list

  • @kruth6663
    @kruth6663 2 роки тому

    The example for value type at 3:25 doesn't look right to me.
    Shouldn't it be like:
    int a = 7;
    int b = a;
    a = 5;
    Debug.Log(b);
    Like this?
    (When you run it it says 7, so your point is proven.)
    Similar with the struct example. When they're both referencing one same instance, the test on both directions are equivalent; But when they're two individual copies, I think the right way to test is to modify the one pointed at, not the one pointing.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому

      It doesn't matter which one you test, with structs they are individual copies completely separated changing a or b would only change that copy, with classes they would be references pointing to the same object, changing a or b would change the same reference.

    • @kruth6663
      @kruth6663 2 роки тому

      @@CodeMonkeyUnity Yeah I get the idea, I just think that it can't be logically proven when the test is done in reverse like this. But anyway, your point is explained clear enough, thanks for replying :)

  • @62mohsen62
    @62mohsen62 3 роки тому +1

    nice

  • @josejimenez-wd5rw
    @josejimenez-wd5rw 5 років тому

    excellent !

  • @godtierslayer3046
    @godtierslayer3046 Рік тому

    I think your describe the information of Value Type and references but I wouldn't say this is a good video because I feel like your not teaching me "How" Value Types work. I've looked over this video a good couple times, like 6-ish and I'm certain you can clarify the relationships better for a beginner to make this more digestiable for someone to learn from. - Constructive critism, your welcome

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Рік тому

      What do you mean by "How" they work? Are you asking how the C# compiler ends up storing them in memory? Like what Assembly code is run and what CPU Registers are used?
      Those are extremely low level details which this tutorial is definitely not intended to teach. The goal with this tutorial is teach you how they are different in how they are used and how they behave, the super low level implementation is way beyond the scope of this tutorial.
      If you want you can get an assembly inspector program and inspect every low level instruction that happens when a struct is created.

  • @Wanfanel
    @Wanfanel 4 роки тому +1

    what about "out" parament

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому +1

      It works by passing a reference, similar to the ref keyword
      The difference is you HAVE to set a value before you exit the function whereas with ref you don't have to change it

  • @me_apps
    @me_apps 5 років тому

    For beginner its better you show them why or when to use it

  • @darrylwolfe7359
    @darrylwolfe7359 4 роки тому

    Question: You said which ones are value types and which ones are reference types. You demonstrated int to show that its a value type. I tried doing the same thing on string types which you said is a reference type so i did this.
    string A = "HELLO";
    string B = A;
    B = "WORLD";
    Debug. Log(A); //outputs HELLO
    If string is a reference type, the output should be WORLD, right?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому

      String isn't a pure reference type, it's a very specific data type with a lot of exceptions.
      In your example yes it works as a value type, but then you can also do string A = null;
      Essentially a string is just a char[] which is stored in memory as a reference to that char[] and not stored as the string contents directly.
      So yes strings sometimes behave as value types and sometimes as reference types.

  • @rahulkumarjha2404
    @rahulkumarjha2404 5 років тому +1

    Are native array reference type or value type ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 років тому +1

      C# Arrays are reference types, so int[] intArray; holds a reference
      However NativeArray is the special DOTS array which is a value type and can be used inside Burst compiled jobs.

    • @rahulkumarjha2404
      @rahulkumarjha2404 5 років тому

      Thanks !

  • @paramitahalder6943
    @paramitahalder6943 3 роки тому +1

    vector3 is a struct

  • @andreicirstea8517
    @andreicirstea8517 5 років тому

    Hi! Great job with these tutorials! Could you please make a video on Rendering with DOTS, like the new RenderMesh, RenderBounds and so on? I am trying to make a grid of nodes using a prefab and when the mouse clicks on one of the nodes i want to change its color but because it's shared it changes all of them. Any ideas?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 років тому +1

      I covered rendering a single sprite and then rendering 100,000 animated sprites. The trick is to use the same material and a different MaterialPropertyBlock
      ua-cam.com/play/PLzDRvYVwl53s40yP5RQXitbT--IRcHqba.html

  • @ri-zg7cv
    @ri-zg7cv 4 роки тому

    Could you add this video to c# playlist, please?

  • @belddap8909
    @belddap8909 3 роки тому +1

    LMAO why is your ad on your own video XD!!

  • @Bandit-is8zi
    @Bandit-is8zi 9 місяців тому

    Lvalue = Rvalue, but not always there are rare situation

  • @TheDiegoPayne
    @TheDiegoPayne 5 років тому

    I don't understand this part: new TestJob { testNativeArray = testNativeArray } ;
    Why testNativeArray = testNativeArray?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 років тому

      You're assigning the testNativeArray field inside the Job with the one made before. There are 2 fields named testNativeArray

  • @ferkxncho
    @ferkxncho 5 років тому +1

    200k face reveal

  • @heavymetalmixer91
    @heavymetalmixer91 2 роки тому

    If objects are reference types and structs are value types, does this mean that objects are more memory-efficient?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому +1

      It's the opposite, objects use more memory because you need to store the object pointer in the Stack and the object data in the Heap
      Whereas a struct is all entirely stored in the Stack which is much faster.

    • @heavymetalmixer91
      @heavymetalmixer91 2 роки тому

      @@CodeMonkeyUnity No wonder Unity focuses more on Structs. What other engines do this?

  • @SaidabrorBrother
    @SaidabrorBrother 9 місяців тому

    2:21

  • @hensi6482
    @hensi6482 5 років тому +1

    WOW IM EARLY

  • @artymationsmobile9744
    @artymationsmobile9744 5 років тому +1

    Early!

  • @DeathxStrike18
    @DeathxStrike18 2 роки тому

    String is actually a value type that lives on the heap because of its byte value can be large and undetermined before initialization and is a combination of char values, where a standard char will be under 2 bytes with exception of some emoji char that will throw an overflow if 3-4 bytes and must be converted as a string as char is allocated 2 bytes. The compiler will actually allocate 12-32 bytes for a string depending on operating system at declaration and double the allocation if the string exceeds it by splitting off the string and then combining it within extra registers.
    If you take your example for reference types string A is still equal to A even if string B = A. chars 'c' + 'a' + 't' have decimal values of c(3)+ a(1) + t(20) and in binary c(01100011) + a(01100001) + t(01110100) = string "cat" = decimal 24 or binary 011000110110000101110100 if using UTF-8bit with 16 bit adding 00000000 before each letters binary. The information that String is a reference type is incorrect.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому

      Not sure exactly what you're talking about but straight from Microsofts website string is a reference type
      docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/reference-types#the-string-type

    • @DeathxStrike18
      @DeathxStrike18 2 роки тому

      @@CodeMonkeyUnity Though Microsoft has it listed as a reference String is a special case it is sometimes a value type and at other times a reference. example you can convert.Int32(string "3") but not "d' though it has a decimal value.
      Using your example you used in the video to distinguish types string will act as a value not a reference stringA = "bird" , StringB = string A, StringB = "fish", Debug.log(StringA) = log = "bird". where a normal reference would update stringA. Even if you did string B = new string(A) A will still store A and B will still store B and will not update A.
      When a string is under 20 characters it is assigned 32 bytes and will be assigned to the stack like a struct. But above 20 characters it will be assigned 64 bytes and moved to the heap to be combined acting like a reference calculation.
      Likely the main reason why a string is classified by Microsoft as a reference is because it can be iterated through like a char[ ] array though it is not technically an array as it does not act like char[ ] arrayChar = new char [ ] would in regards to reference.

    • @DeathxStrike18
      @DeathxStrike18 2 роки тому

      @@CodeMonkeyUnity Nm you are correct I realized its because a new instance is created every time a string is declared as if string S = new string("some value") every time, what makes it a reference is because a reference for the variable is stored on the stack but the actual data is being stored on the heap.

  • @lem.
    @lem. 5 років тому

    Hey dude you can do a MOBA game like lol offline or online, you know if you see this please do that video if you want :D bye
    (yhea i copy this form the other video you uploaded XD)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 років тому

      Making an entire MOBA is a bit too complex for a single video but I have thought about doing some elements from it like doing the Enemy Spawning and AI

    • @lem.
      @lem. 5 років тому

      @@CodeMonkeyUnity yhea i know it's complex but you can make a serie of videos like a video of "minions spawning" and the other is "character selection" you know step by step only if you want :D

  • @ns1755
    @ns1755 5 років тому +1

    5 SECONDS AGO

    • @artymationsmobile9744
      @artymationsmobile9744 5 років тому +1

      We're so EARLY!

    • @ns1755
      @ns1755 5 років тому +1

      No way did he like me comment! I would just like to say you inspire me! You are talented and are just the best at these types of videos. Thank you so much 😊

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 років тому +1

      Glad to hear it!

  • @madhukasasanka-vp7ms
    @madhukasasanka-vp7ms 9 місяців тому

  • @sumitdebbarma1209
    @sumitdebbarma1209 3 роки тому

    sir explaination is very fast i cant catch up.

  • @raphaeljaggerd3585
    @raphaeljaggerd3585 4 роки тому

    He lost me with the DOTS implementation

  • @jonathanjones2435
    @jonathanjones2435 4 роки тому

    am I crazy... or would it be better if there were to operators for assignments? an '=c' operator for when a copy is assigned... and an '=r' or something when you are assigning a reference. something like that. I decided to spend all this free time i've had this year from being locked indoors to learn Unity and GameDev. Now... I'm finding I need to learn C# and it's infuriating how illogical it all is. Like... I watch ten thousand tutorials on object oriented programming and classes and I think I understand it.... then I'm writing code and I'm like... wtf is vector.forward? I'm using it all the time but I never instantiate it. And now I'm learning that Vector3 is a static struct and NOTHING like a class....and now I know nothing all over again. sigh...

    • @__________________________4597
      @__________________________4597 3 роки тому

      So.. the reason there is a difference is because of.. Minimizing memory consumption. It is all based on optimization within C. A cool feature of a language like RustLang is that every type is a value type. (If I am correct). And you can do what you said. basically, make something mutable/copyable, etc. But then again. RustLang doesn't use objects.
      I wouldn't look too much into tutorials if I were you. And instead, do the Try and Error method. Together with reading up on Game Design Patterns. As this would prob help you a lot more. Something which helped me with learning how to program well is to make game systems. Not a game. Just a system you could use in one. And then see where is falls short and how to do it better next time.