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
  4. Dismiss Notice

1000 Animations Performance

Discussion in 'Animation' started by zuhairi, Oct 22, 2017.

  1. zuhairi

    zuhairi

    Joined:
    Mar 11, 2016
    Posts:
    2
    I am making a dictionary that would list 1000 words, and everytime one word is click, a panel will pop up and show 2 UI Object; Word Selected and Animation of that word.



    Performance wise, how should I setup my game object ? Should it be a 1000 inactive gameobject and activate it depending on which word selected ? Or I create one gameobject and change animation programatically ?
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,531
    One GameObject programmatically. The GameObject can have a UI Text for the word.

    Separate data from code. I recommend a spreadsheet containing 1000 rows. Put the word in column A and the name of the sprite in column B. Save the spreadsheet in CSV format so it's easy to read in a script, such as:

    Animal,alligator
    Boat,tugboat
    Cat,housecat
    etc.

    Put those sprites in a Resources folder so you can load them at runtime.

    When the user clicks on a word, set the UI Text to the word. Use Resources.Load() to load the sprite, and instantiate it as a child of the GameObject, deleting any previously-instantiated sprite.
     
  3. CaseyLee

    CaseyLee

    Joined:
    Jan 17, 2013
    Posts:
    40
    uhhh, no.

    Hes asking about performance, and when considering performance one should not be using the resource folder. Not with 1000 sprites, ffs man...

    from unity docs " Resource folder Best practices: #1 Don't use the resource folder"
    https://unity3d.com/learn/tutorials/temas/best-practices/resources-folder


    Edit: oh ya, as for a best performance solution would involve a texture atlas of some sort.
     
    Last edited: Oct 26, 2017
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,531
    Given that the OP is asking at this level ("should I manually create 1000 separate GameObjects?"), Resources.Load is appropriate for the current degree of experience with Unity. And, given the purpose, there's practically no difference between using a sprite atlas or loading from Resources; in this scenario they'd both be loading at start, and the size of the build would be the same. It's just a matter of evaluating current experience level with Unity, and current requirements, and fitting an appropriate solution.
     
    MaximeChaos likes this.
  5. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,131
    I have not tried it but in 2017, there is a new Sprite packer "Sprite atlas" - I understand it is pretty much as resources load (I.e. You would have to reference the individual sprites in code) but with the benefit of the sprites being in one or more textures. You basically have to create the Sprite atlas as an asset.

    In the old world with Sprite packer, you could also just import them (I.e put them in your asset directory) give them all the same Sprite pack tag. Then you could drag them into an array / list and for convenience auto create a dictionary<string, sprite> and access them by file name. If you actually have not only one, but multiple sprites per word (you said animation) I think this approach could also work.

    It's not 100% clear to me what exactly you want...(are you having 1000 words and 1000 sprites or 1000 Sprite animations)