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

Most efficient way to swap between models?

Discussion in 'Scripting' started by Happystudio, Mar 2, 2015.

  1. Happystudio

    Happystudio

    Joined:
    Mar 1, 2015
    Posts:
    4
    What is the most efficient way to swap between in game models, given the two scenarios:

    1) Model 1 -> Model 2 -> Model 3
    2) Model 1 -> Model 2 -> Model 1 -> Model 2

    Would it be better to just show hide the objects with activate/deactivate? Or is it better to destroy the old one and instantiate the new one at run time?

    Would the answer be the same for both scenarios?
     
  2. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    If memory is not a concern, then have them all loaded when the scene loads and
    then just activate/deactivate when required.

    If memory is a concern, then let
    them be instantiated at the right time, however, depending upon the kind
    of model you are instantiating, there could be a drop in fps.
     
  3. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    For both of your scenarios:
    1. Destroying and instantiating is the least efficient. Avoid it if you can.
    2. Activate/Deactivate is much better.
    3. Object pooling is as good as #2 and looks a lot like #1.
    4. renderer.enabled = true / renderer.enabled = fasle is the bestest, but might not work in every scenario.