Question regarding types of common components for an ECS system (C++)

Started by
2 comments, last by hplus0603 2 years, 8 months ago

Hello,

So I've completed an entity component system. I had a few questions.

  1. Is it common to consider the tile map itself a component? Assigning it a sprite component, transformation ect? Or is this generally separate from it all? It seems like it would bloat up the ECS having 10,000 tiles (for example).
  2. What are some more popular/common components to add (data structures)? At the moment I have a transform, rigidbody, sprite, camera, boxcollider, textlabel, health, script (for reading scripts), projectile, animation, input and the corresponding systems. Of course this might really depend on the type of game you are making, but I'm just trying to see if there is anything standard that I most likely will be adding anyways? I can't seem to find anything on github that shows a more complete example of what they used? I might just look into what Unity and Unreal provide, but this is strictly 2D at the moment.
  3. I haven't created some type of pathfinding, because I have yet to decide how to go about the tile map.

Any advice or tips would be appreciated.

Thanks, take care, be safe.

Advertisement

LedMar said:
Is it common to consider the tile map itself a component? Assigning it a sprite component, transformation ect? Or is this generally separate from it all? It seems like it would bloat up the ECS having 10,000 tiles (for example)

From my experience, they're handled similar to texture atlasses simply as an asset without any component, or do you plan something special which involves a system? If it's an “editor only” thing, you could use editor components if necessary.

LedMar said:
if there is anything standard that I most likely will be adding anyways?

I think there is no standard thing except for what you already wrote about. If you go for 2D only at the moment, anything mesh specific might fall under the standard stuff too but as you're not using it, I think that's it so far.

LedMar said:
I might just look into what Unity and Unreal provide, but this is strictly 2D at the moment

You could anyways have a look !?

LedMar said:
Is it common to consider the tile map itself a component? Assigning it a sprite component, transformation ect? Or is this generally separate from it all? It seems like it would bloat up the ECS having 10,000 tiles (for example).

No, I wouldn't make each separate tile a component, thats really bad. Implementation-wise, my tilemap uses a uniform grid consisting of only points, that are being extended with a geometry-shader - this is really fast, even if you have huge maps with large zoom (my largest map is 500x500), sprites would be way to slow for that.

Now you can make your whole Tilemap a component, if thats what fits your design best. I personally handle my tilemap outside of ECS since there is always 1 tilemap per scene, but its totally valid to just have the tilemap be part of an ECS like that.

For something that is “one big thing,” you can build it as a subsystem, or you can build it as a series of interacting components.

Having each tile be a separate object is generally not going to work out well, if for no other reason than because calling a virtual function for each tile to do anything will cost tons in performance.

In 3D games, the “terrain” (if it's a heightmap) will often be its own object, which either has one specialized “terrain component," or breaks the terrain down into “chunks” where each chunk has a “terrain chunk component.” You could do the same with the tile system if you want.

The other question is: What do you expect to use this component for? The purpose of using components, is generally to get a good abstraction for individual data items. This helps in savegames, it helps in game editors, and it helps in networking. But, a tilemap is “a thing” on its own, where there is significant benefit to treating it as a regular grid, so making each tile be a component doesn't strike me as a well motivated design choice.

(It's always important to know why you're doing a thing! Sometimes, we do things out of habit or dogma, that turn out to actually go against our real goals. Recognizing this and having the fortitude to do what's right for the problem at hand, is an important meta-skill.)

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement