I’m learning Unity and wanted to check about what uses are appropriate for ScriptableObjects, specifically for tile maps.
I’m creating a tile map system and am figuring out a way to represent tile sets (the palette of tiles a map uses). A tile set needs all the tile images - in my case a texture atlas since my maps are single meshes - and game data for each tile like whether a tile blocks all objects or if it just blocks projectiles.
Would this be what ScriptableObjects are for? Or would you recommend a different system for managing my tile data?
Yes you can use a ScriptableObjects for exactly that. I’ve used the to create a complete data base of my game.
I’m not sure how you have your tile sets layed out already. ScriptableObjects are really just for Data , that are basically independent of GO’s (gameObjects) . As for you, there are two things most TileMap systems have.
Your map Format that tells us how the maps is constructed with the tile set. its up to you how you do this.
And your tile set its self that contains any images as well as specific tile related data e.g Transpareceny / Terrain damage for RPGs
Since your tile set can be applied to many maps , it can be saved as a .asset file. that way much like a prefab it can be stored and used whenever it is needed. in order to effectively achieve this writing an editor script will be needed.
Well, my tile images come in as separate files, so I need to first generate a texture map.* I thought I’d do that with a script calling Texture2D.PackTextures. I was unsure though what I’d attach the atlas generation script to and where to put the resulting texture and atlas data.
For the tile map itself, I’ve gotten as far as having a GameObject with a script that generates a mesh of quads. I’ll need a way to reference a texture so that I can UV-map the quads, and I’ll need a way for the map tiles to know the game data for their tile types.
So I was wondering if a ScriptableObject would be appropriate, where it could take a collection of tile images, game data for each tile type, and have the texture atlas generation script. Tile maps meanwhile would have tile set ScriptableObjects as a property. I figured ScriptableObjects would be appropriate since tile sets themselves wouldn’t be in-game objects like GameObjects, and I assumed ScriptableObjects could be saved as asset files anyway. Am I understanding things here correctly?
Actually, I’d use Sprite Packer except there’s apparently no way to get the result texture.
Buying a package from the Asset Store is currently not an option for me.
How would I use Unit sprites though, aside from just creating a bunch of individual sprites and arranging them in a grid? Because I thought you couldn’t access the texture generated by using packing tags and Sprite Packer, which I’d need for assigning to the tile map’s material since it’s a single mesh (should it be a single mesh?).
So, I should abandon the “tile maps are a single mesh of merged quads” approach then?
Well, using plain sprites would be a bit easier than working out the mesh generation logic, I suppose. And it would make it easier to manage things like having overlapping tiles and toggling the visibility of certain tiles. And instead of using a ScriptableObject I could instead have each tile be a prefab of a sprite + tile data script. Right?
No, you’d use ScriptableObject. SpriteTile doesn’t make a GameObject for every tile in the level; that would be far too many. Instead there is a pool of sprites that fills the screen and the sprites are recycled as needed.