Search Unity

Changing Image.Sprite at runtime vs having one gameobject per sprite.

Discussion in 'Scripting' started by blablaalb, Jan 12, 2019.

?

What is more performance efficient

  1. Changing Image.sprite at runtime

  2. Having a GameObject per Image.

Results are only viewable after voting.
  1. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    53
    I'm making a HUD for currently active weapon and I'm wondering what would be more performance efficient: having a one GameObject with Image component and changing its sprite via script (`Image.sprite`) at runtime or having one GameObject per image and activating/deactivating them.
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Neither will have any real significant impact on performance. I'd personally go with just one GO with an array or list of possible sprites you can swap to, as it's more straight forward on how to add or remove ones during development.
     
    Dfyzet likes this.