#How would i handle this D.O.T.S problem?

1 messages · Page 1 of 1 (latest)

lone wren
#

so, i'm building a tilemap system and i'm trying to figure out how to handle tiles in dots. my current mono behaviour setup looks like:

-> Chunk (TileChunk Script)
--> Tile (Tile Script)
--> Tile (Tile Script)
-> Chunk (TileChunk Script)
--> Tile (Tile Script)
--> <...etc...>```
basically the Tilemap script manges what chunks should be loaded, easy to convert to ECS
the Chunk Spawns Tiles, easy to convert to ECS
the Tile... this is the hard part, it needs to be extendable. so for example a subclass of tile could override onClick so the tiles texture changes when its clicked, or maybe a subclass of tile could override onWalk that acts of a pressure plate triggering other tiles.
How would i implement this in ECS?
dense igloo
#

You'll esentially want composition over inheritance: https://en.wikipedia.org/wiki/Composition_over_inheritance
Instead of thinking of it as "I have x types of tiles with different behaviour", think of it as "I have x different behaviours that I can combine to make unique tiles".

There's a few ways to do this, you could for example have a "TriggerOnWalk" component that has a reference to the tiles you want to trigger once you walk onto it. When you walk onto a tile you can check if it has this component and run the logic for it if it does.

Alternatively you can have a OnWalk component that takes a function pointer that gets called when you walk onto the tile. Then you wouldn't need different types of component per type of walk behaviour, but you lose some performance and code cleaneliness.

There's also the option of storing the tiles as an array of enums instead, each enum having the type of tile stored in it.
Then on walk you can just do a switch over the enum and implement different behaviour based on what enum it is. This works best if you don't need any specialized data on the tile (I.E. if the tile always activates other tiles within a certain radius, rather than being tied to an arbritrary tile).