Reducing number of GameObjects being spawned

The game I’m creating has tiles, units, abilities, etc and all of these are their own syncable GameObjects because they all have their own complex data structures and I need them to be able to easily reference each other for various different cases.

The one I’m most currently concerned with is the tiles. It is a tile-based game, so a map could potentially have 1,000s of tiles that all need to store synced data. It is a turn-based game, so technically, these tiles only need to be synced once per turn, lets say, 50 times per game.

I don’t know actually what the max tiles will be yet, I want to test it out and get a feel for it, but currently spawning 100 causes a few seconds of lag, so testing max scale is not something I’m going to venture just yet.

I currently spawn them all at once when the game starts. I could spawn them over time in the game lobby to help with that, but that’s sort of less of my concern.

My real concern is that if I am running MRS with 1,000s of tiles in each room, this seems like something that I should optimize because even now it would be helpful to create the maps I’m really going for, not to mention reduce server demand in the future.

Theoretically in Coherence, it seems like I could convert all the tiles into byte arrays and have a single byte array for each map of tiles and reduce 1,000s of tile GameObjects into a single tile map GameObject… and I might end up doing this.

Before I do though, I wanted to ask what your thoughts are on handling this kind of issue, and if there are any better ways than what I’ve mentioned here.

Hi @Neodamus !

Sounds like it is potentially a large amount of data.

If the state doesn’t change very often, perhaps you could avoid having a single entity for each tile, and use a single entity instead with a Command that you can use to update the state of a specific tile?

I don’t know how you’re generating the tiles, but if you manage to make it so the tiles are generated deterministically, so each tile has the same ID in every client, you can use that ID to soft reference each tile and update their state via commands instead of via synced fields.

1 Like

Thanks for the response @miguel-coherence

So the tiles do all have a synced ID, pretty much every type in the game does.

I do think sending commands only when I need to update the tiles makes more sense than having synced values since the updates are probably like ~1min apart or so.

Also, there’s probably only 10-20% of tiles max that would change state per turn, such as tile is now burning or frozen, or unit has moved on/off it, etc.

So, I’m imagining a single entity having a List of Tiles as a property and every turn, it sends a command to all clients to update the tiles that have changed state.

In this case, the command I send would probably need to be a byte array? Like each tile state change update is a few bytes; the first byte is ID and then a few other bytes to transmit state changes to that tile, and maybe empty byte to separate tile state updates from each other in the byte stream since a tile state update might not have a fixed amount of bytes.

Alternatively, I could send a command for each tile update, but this could end up being 100s of commands at once to each client, and seems less ideal than a command with a batch of updates, but maybe there’s no real difference in performance here.

Does byte array seem like the structure to use here? It is the only supported type I’m aware of that can send complex data like this, but maybe there’s something easier to use I’m not aware of.

EDIT: I do also know of this Creating your own syncable member | coherence Documentation … I’m not sure I 100% understand this as I haven’t tried to use it, but maybe it’s possible I can describe how a Tile should be synced as a type and not have to use byte array?

1 Like

Yes you got it right, using a byte array would be the way to go here and what you described is exactly what I was suggesting

1 Like