Search Unity

[Unity2D] Performance-wise handling layered character (sprite sheets)

Discussion in '2D' started by TheCodeTherapy, Feb 21, 2016.

  1. TheCodeTherapy

    TheCodeTherapy

    Joined:
    Aug 11, 2013
    Posts:
    1
    Hello there!

    Right now I'm working on a project which will use pseudo-randomized characters as Players and NPCs. Each one of those will be composed by "layered" pixel-art sprite sheets (the sprite sheets types are: character body (base), eyes, clothing, weapon, hair). All the sprite sheets were composed foreseeing the project, so they're all coherent concerning sprites count, position, size and order so I can overlay them, even with a sprite-based animation consistent reference. That said, in a practical perspective, I can overlay, for example:

    - prefab made with character base (body) sprite sheet type 2
    - prefab made with eyes sprite sheet type 4
    - prefab made with clothing sprite sheet type 3
    - prefab made with weapon sprite sheet type 5
    - prefab made with hair sprite sheet type 1

    That way, overlaying the prefabs, and assigning the same animator and controller to all the prefabs, I can handle 1 character properly, and get it flexibly customizable and behaving exactly as I want it to. My problem emerges thinking about performance and scalability, as I need to spawn multiple characters on the same scene with different compositions.

    Right now there are a total of 156 sprite sheets ( 10 body types, 7 eyes types, 12 outfit types, 6 weapon types, 48 hair types... So, 241.920 possible combinations). All the sprite sheets are 512x512px PNG-8, and they all together represent just 1.82 MB on disk (as images)... but as you all know, it's a totally different story once they're imported to Unity and start being loaded on memory.

    My concerns are:

    1) Memory consumption... Each time I instantiate all the 5 prefabs necessary to compose each single character (with 5 different sprite sheets), it's all loaded in memory, and there's not much I can do about it afterwards (right?).

    2) Draw calls... I already wondered about programatically "merging" the sprites desired to compose a character into a new single one before spawning the character, but I'm afraid I can get into a whole different nightmare. I also wondered about using (outside of Unity's scope) Imagemagick's composite (Linux command line tool) with a simple Python script to generate every single 241.920 possible combinations of sprites (just trying to consider every possible approach here ok? I'm not crazy, says my psychiatrist).

    That said, with a learning emphasis in mind, I'd like to read different ideas and perspectives from you, ladies and gentlemen, concerning my project. (can't stress enough my Unity educational purpose with this thread, so answers unlike "are all those combinations really necessary?" will be immensely appreciated).

    I hope some of you find this discussion interesting.

    My best regards.
     
    theANMATOR2b likes this.