Search Unity

Question Does someone know what ''Create" does exactly?

Discussion in 'Visual Scripting' started by Marou1, Dec 2, 2022.

  1. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    161
    Hi,

    Could someone explain what this node does exactly?
    upload_2022-12-1_19-14-50.png

    I understand that it creates an instance of the class Building Data. But if I don't store it in a variable, does it stay in memory? Do I have to destroy it?

    Let's say I have a script that contains only this:
    upload_2022-12-1_19-23-19.png

    Does it means it will create dozens of instances every second?
    If yes, how to destroy them?

    My concern is to avoid creating a lot of instances that use memory and affect the performances.

    Thanks
     
  2. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,068
    "Create" is UVS' way of describing "new" operator. And they're cleaned up automatically. C# and therefore UVS is a managed language - memory is automatically handled by the garbage collector. Google managed vs unmanaged programming languages to learn more.

    So some pure data instance won't crap your memory full, even if you have thousands of them. Also you should not be creating new instances in Update.
     
    Last edited: Dec 2, 2022
    Marou1 likes this.
  3. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    161
    Of course, I was giving an extreme example.
    Thank you for the explanation.