Search Unity

Newbie help - Tilemap, Sprite Atlas and modded assets

Discussion in '2D' started by rustic_philosopher, Nov 21, 2022.

  1. rustic_philosopher

    rustic_philosopher

    Joined:
    Nov 17, 2022
    Posts:
    22
    Hey All,

    First off, apologies - I am still wrapping my head around a lot of Unity concepts and behavior so I will be peppering in a bunch of stupid questions.

    High level overview of what I trying to play with in Unity: 2D game world programmatically created using Tilemap, Grid, etc and loading world data from JSON. I am hobbling my way through a lot of the Tilemap stuff but one thing I am curious about is how to handle modded resources.

    For example, say a player goes "I hate the stock peach in the game - I want to add a magic peach" and then creates a mod that has a JSON file containing new stats for the item and a png for the what the magic peach looks like.

    Now, my understanding is that I should use Sprite Atlas to keep things performant in game but I am not sure how to dynamically build a Sprite Atlas and add then be able to dynamically add sprites to it based on finding a new image file in a configured location on disk (where the modded resources would be put).

    I am sure there are questions I don't know enough to ask so please feel free to volunteer information and steer me in the right direction.

    Thanks in advance!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    It sounds like you need to first make a prototype of your game and when it reaches critical mass, try modding it.

    Otherwise it's all guesswork.

    Your biggest problem will be to get players, let alone players willing to go through the hassle of modding. In the 40 minutes between your post and my reply, there have probably been over 100 new games created worldwide.

    Some modders just swap assets, some write entire editors, and there is absolutely no way for you to anticipate what they might do. Just make your game, let the modders mod.
     
  3. rustic_philosopher

    rustic_philosopher

    Joined:
    Nov 17, 2022
    Posts:
    22
    I am not even really trying to release a game here - just playing around and curious about the engineering solution to the problem I pose vs needing help on how to build a community. So how can I build / modify a Sprite Atlas programmatically if I have assets I need to load at runtime?
     
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    SpriteAtlas does not support dynamically adding sprites to it. You have to roll your own solution to it.

    You might consider this https://davikingcode.com/blog/unity-generate-spritesheets-at-runtime/
    Github: https://github.com/DaVikingCode/UnityRuntimeSpriteSheetsGenerator

    There are also paid solutions on the asset store.

    A simple first step is to have no solution and let your dynamically added sprites break batches by virtue of not being part of any atlas/spritesheet. This is less performant, but players understand that mods tend to decrease performance. Once you have people seriously interested in modding the game (Kurt's point), then you can add a dynamic solution.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
  6. rustic_philosopher

    rustic_philosopher

    Joined:
    Nov 17, 2022
    Posts:
    22
    Interesting and certainly not opposed from a technical perspective but doesn't that still leave the issue of how to create the SpriteAtlas from that location or are you just saying dont worry about the atlas at all for any of the sprites? If so wouldnt that be a major issue performance wise even with setting mod support aside?
     
  7. rustic_philosopher

    rustic_philosopher

    Joined:
    Nov 17, 2022
    Posts:
    22
    "let your dynamically added sprites break batches" - sorry, not following what you mean by this?

    In general though - how important is it really to put sprites into sprite atlases performance wise? Does it make a big difference or does it fall into a more gold plating kind of category?
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Oh no, you would need to do all the atlassing yourself, tile the sprites together, etc. Or just chop the sprites out yourself, probably from some type of JSON datafile.

    Sprite atlassing is an EXTREMELY well-understood process. Anyone can write a sprite atlasser, something that combines sprites into a single texture. You just have to write it, or else integrate an existing one.

    There's an actual reason we use Unity. It's awesome and it does all these things for us. But it does them in the EDITOR, not in the RUNTIME, which is where the modders all live.

    By all means, spend your programming time where you like, but rewriting a perfectly functional sprite atlassing system just so that some imaginary future strangers who MIGHT want a different princess peach in my game is NOT where I will be spending my time.
     
  9. rustic_philosopher

    rustic_philosopher

    Joined:
    Nov 17, 2022
    Posts:
    22
    I appreciate the information but you keep describing this in the context of what makes sense in terms of releasing a product or like I am arguing about what makes sense business wise. I get it, Unity saves time, etc etc but my questioning has been purely from a hypothetical engineering perspective of "how would you do this if you wanted to" vs "I need to do this". It's normal engineering curiosity to like to know how things work and what all the options are.
     
  10. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    When sending stuff to the GPU, Unity groups together what it can to send more in a "batch." The GPU will hum along processing a nice big batch. But if you give the GPU a bunch of little things to do, it can spend a lot of time idle simply waiting for the CPU to send it the next thing. It is also costly to tell the GPU to change its state.

    To qualify to go into the same batch, objects need to share a lot of properties - including the texture. Atlasing combines the textures so a set of similar sprites do not break the batch.

    https://docs.unity3d.com/Manual/dynamic-batching.html

    The Frame Debugger will give you information about why two batches broke.
    https://docs.unity3d.com/Manual/FrameDebugger.html

    There's also a new, different thing in URP called the SRP Batcher but I'll just earmark that rather than go into it here.

    Unfortunately it can matter "a lot" to "a little" depending on the scene. If you have a scene with many sprites, its absence matters a whole lot more. But if we're talking about a modded sprite here or there, then increasing the batches 10% isn't very much.
     
  11. rustic_philosopher

    rustic_philosopher

    Joined:
    Nov 17, 2022
    Posts:
    22
    Interesting, thanks.
     
  12. flasker

    flasker

    Joined:
    Aug 5, 2022
    Posts:
    193
    if someone wants to mod your game they dont need your help to do it, they will do it their own way

    look at stardew valley for example it has no modding support but tons of mods

    minecraft the same.

    its sort of like a hack, they will just decompile your game and add new code

    all that i want to say is that almost no one makes their game with modding support, but people will mod it anyway, and they will do it better than you. ( For example modders made stardew valley multiplayer 2 years before the legit multiplayer was released since the original creator didnt know how to make multiplayer )
     
    Kurt-Dekker likes this.
  13. rustic_philosopher

    rustic_philosopher

    Joined:
    Nov 17, 2022
    Posts:
    22
    Again, it's not a question about whether its needed or not to support a player population. The question as described above is around engineering curiosity and how you could create a framework for easy import of assets, rules, etc with modding being an example of the model.

    That said, to your example I would actual compare a game like Rimworld where modding is supported to Stardew Valley and I think the quality and volume of mods is drastically different as data points. Either way, the ROI on modding support is an aside from the technical approach itself.