13 votes
Accepted

Should I implement Entity Component System in all my projects?

Short version: no, your job as an engineer is to evaluate all applicable solutions to problems before choosing a solution Long Version: "ECS" is an overloaded term. It had a somewhat clear ...
11 votes
Accepted

How do I define a required component on a Unity game object?

Applying the RequireComponent decoration to a script will ensure that the GameObject has the specified component. If the component is missing: Unity will attempt ...
  • 3,842
11 votes
Accepted

Updating a multithreaded Entity-Component-System

The simple version: don't. One could argue that you have perhaps a slight misunderstandings about how to build an ECS (why would you sent a list of Entity* to a system to update? the System is ...
10 votes
Accepted

Creating a Static function inside my class to handle small housekeeping tasks

In C#, having an instance (non-static) method in a class does not copy the instructions for each object created from that class. Static or not, the data that represents the instructions only exist in ...
10 votes

Would it be better to use XML/JSON/Text or a database to store game content?

Im late to the party here but I spent A-LOT of time researching this. First why I don't use the following: XML: Excessively verbose. Tons of redundancy. Repeating field names? GROSS JSON: I think ...
  • 233
10 votes
Accepted

A more data oriented design approach to Entity Component System game engine

What's an object? What we call an object or an entity depending on the model is, fundamentally, made of two parts: data, and behaviour. Game objects have properties and do things. Let's take a ...
  • 1,158
9 votes

Complex system-component dependencies in entity-component-system?

First, you should not have a strict 1-1 mapping of Components to Systems. It's unclear to me from your question if that's the case already. You may very well have singular systems that use or interact ...
8 votes
Accepted

How do components access one another in a component based entity system

Components are just a collection of data and logic. How you store and relate them to the logical entity is where you gain or lose performance depending on the strategy you choose. My example and ...
  • 1,728
8 votes
Accepted

Dealing with more complex entities in an ECS architecture

Games typically approach this type of issue using a transformation hierarchy. In this model, each entity can be treated as a "child" of a "parent" entity. The entity's local ...
  • 122k
8 votes
Accepted

What should be an entity/component, and what shouldn't?

A lot of systems in a game that needs to be updated are things that are not rendered and don't need any input, they simply need a call to their update function every frame. They don't have any ...
  • 122k
6 votes

Component oriented programming for rich RPG world

Taking the example of the guitar: (...) a player you can, for example, not only play on guitar as a Musical Instrument, but use it as a Weapon or, what is perhaps more unobvious, throw it right to ...
  • 20.4k
6 votes
Accepted

What is a faster alternative to a GetComponent from a RaycastHit?

You could use a Dictionary. Store all Transforms as a key with reference to each Car. In this example, we have a god Game class that holds references to all Cars. (just make sure your Script ...
5 votes
Accepted

How to manage state in a component-based game engine?

It's OK to have component dependencies. And the more explicit the dependency the better. There's nothing worse than dependencies hidden behind useless layers of indirections. Your case doesn't look ...
5 votes
Accepted

Appropriate Cache Friendly Associative Container For An Entity Component System

Do the simplest thing that works, especially early on. If you've ever seen videos of triple-A titles in alpha, you'll know how slow / buggy they are. This is normal; in fact, it's desirable. And it's ...
  • 29.3k
5 votes
Accepted

How to react properly to component field changes?

I personally would go with the event sending, because it's more explicit and easier to follow in code. Something like: ...
5 votes

Should components in Entity Component System pattern have logic?

I was considering voting to close this question as opinion-based, but I think there are a couple of misunderstandings about Entity-Component Systems and Data-Oriented Design here that are worth ...
  • 122k
5 votes
Accepted

How to make a component solution in Godot (similar to Unity's)

A component solution For convenience, not necessary for functionality, let us export an "archetype" variable: export(Array, GDScript) var archetype:Array ...
  • 20.4k
4 votes
Accepted

Who Handles Collision in a Component Based Entity System

I'll try to explain with an example: Let's say we have an RPG where you can enchant your weapons with elemental damage. The weapon still have a "physical" attack power, which is reduced by the ...
  • 344
4 votes
Accepted

Access Entities components via the Entity that holds them, or via a separate System?

I would recommend having both. Entity/Component Graph This defines which entities are attached to which components. In my engine, there is no such thing as an "entity", but any component can have ...
  • 3,597
4 votes

How can I support component-to-object communication safely and with cache-friendly component storage?

Being 'cache friendly' is a preoccupation big games have. This seems to be premature optimization to me. One way to solve this without being 'cache friendly' would be to create your object on the ...
  • 16k
4 votes

How do components access one another in a component based entity system

Your component entity system doesn't match that which was shown in the article. The article doesn't attach logic components to entities, it uses system objects which look for data components. ...
  • 1,713
3 votes

Client-Server Game Communication (w/ Protobuf, Relevancy and Delta Compression)

My solution has been to combine both 1 and 2 into a "watching me list" on each object. When adding a client to an object's list, it sends a full state packet. Then on each update, it can send a delta ...
3 votes
Accepted

Unity3D - GameObject as a static function

That's not using GetComponent() on the class GameObject, it's using GetComponent() on the result of GameObject.Find() GameObject.Find() is a static function, but it returns a specific object. Note ...
  • 15.7k
3 votes

How to manage state in a component-based game engine?

In my experiences there aren't too many ways around the fact that, you're right, all your different game entities and their components need to be aware of the state of the game and their own state. It'...
  • 1,373
3 votes

How do I define a required component on a Unity game object?

Unity has built in functionality for this called RequireComponent. Used like this in Unityscript: ...
  • 72.9k
3 votes

Transform components in ECS

The TransformComponent idiom is common in most component-based engines, not just ECS engines (note that with Unity there are no "Systems" related to ...
3 votes

ECS: AI components and systems

The problem I see with this approach is that the AI module cannot be easily decoupled from the components attached to the entities. To evaluate a tree or run a state machine, it needs to know ...
  • 29.3k
3 votes
Accepted

How to disable script component while in game?

Assume that you have a script like so: ...
3 votes
Accepted

ECS - Components inside components?

First of all, there is no "right" or "wrong" way to structure a game's software architecture. Just ways which work or don't work for you. Usually you wouldn't nest components. What you would do ...
  • 114k

Only top scored, non community-wiki answers of a minimum length are eligible