Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Instantiate

Discussion in 'Scripting' started by tawdry, May 30, 2018.

  1. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Hi
    Just curious on instantiate and its memory use.
    For example lets say i make a build and have a script to instantiate an object ,the instantiated object textures etc are loaded in memory when the game is run, or only after it is instantiated?
    And follow up question if that instantiated object is then destroyed can it again be instantiated or is it wiped completely?I know in the editor i can instantiate and destroy the same object as many times as i want but not sure if the same applies to a build ?
     
  2. Pavlon

    Pavlon

    Joined:
    Apr 15, 2015
    Posts:
    191
  3. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Specifically want to avoid pooling for a lot of the stuff while i will use it for the less memory intense stuff i already know about pooling want to know the instantiate destroy workflow and its effects on ram.
     
  4. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    For instance if i already have a reference to an object for instantiation just waiting to be triggered is that object preloaded into the ram.If i load it instead from resources folder would that be more ram friendly?
     
  5. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,315
    You can never instantiate and destroy the same object more than once. Every time it is a new instance. What you are instantiating is a copy of an original object (usually a prefab).

    The resources for that object will be loaded when the scene that contains it is loaded. If you load it from Resources it will be loaded when the Resources call is made.
     
  6. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Ok thanks maogvox so Resources.load it will be for me then.