Skip to main content
14 votes

What's the appropiate way to achieve composition in Godot?

I have gone from a monolith player controller, to an state machine, to a behavior tree, to something closer to what you describe. My current character controller looks something like this in the scene ...
Theraot's user avatar
  • 28k
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 ...
Quentin's user avatar
  • 1,188
10 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 ...
DMGregory's user avatar
  • 139k
9 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 ...
DMGregory's user avatar
  • 139k
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 ...
Stephan's user avatar
  • 1,738
7 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 ...
DMGregory's user avatar
  • 139k
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 ...
Chris McFarland's user avatar
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 ...
Engineer's user avatar
  • 30.4k
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: ...
Smilediver's user avatar
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. ...
Krupip's user avatar
  • 1,793
4 votes

Would it be practical if I used composition for everything?

Composition is a tool. Always use the right tool for the job. Of course you can use a screwdriver to hit a nail. But using a hammer might lead to faster and cleaner results. Composition is a pretty ...
Philipp's user avatar
  • 122k
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 ...
Engineer's user avatar
  • 30.4k
3 votes
Accepted

Where is 'game logic' implemented in component based design?

Not everything in your game must be based on the ECS pattern you're using and the game logic might be a good candidate not to. It could be a global script. Or, as you mention, you can implement the ...
rickyviking's user avatar
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 ...
Philipp's user avatar
  • 122k
3 votes

Why even use coroutines in Unity?

You can do that if you want, but... First, 10000 update calls are more expensive than one update call calling 10000 functions. This is due to the Magic Method indexing and querying logic Unity does ...
Draco18s no longer trusts SE's user avatar
3 votes
Accepted

Unity get component throwing NullReferenceException only in standalone build

I found the problem. It was all because of a stupid little workaround I was making. For some context, I was having problems with the new prefab workflow resetting scene references in all my levels. I ...
mr-matt's user avatar
  • 2,769
3 votes
Accepted

Should fields in components in an ECS use polymorphism?

feels like I'm violating the ECS rule There is no ECS police that will come and put you in ECS Jail. This is your architecture, you set it up how it fits your needs. having any functionality in ...
Vaillancourt's user avatar
  • 16.4k
3 votes

Cannot decide between using a MessageBus and entities for events in my ECS game

My approach was to have a PhysicsSystem which works on entities that have a ColliderComponent/PhysicsComponent/TransformComponent...
nenchev's user avatar
  • 141
3 votes

How to Implement ECS Archetypes in C#?

Here is a sketch of how you can implement an archetype in C#: ...
DMGregory's user avatar
  • 139k
3 votes
Accepted

Decoupling Components

One great tool for decoupling components in Unity are events. The high-level idea of events is that one component says "Something happened with me" and other components can choose to ...
Philipp's user avatar
  • 122k
2 votes
Accepted

Component based architecture in TypeScript

I've got some good suggestions on Phaser forum, the solution shown by user @flyovergames was what I was looking for: ...
Guilherme Recchi Cardozo's user avatar
2 votes
Accepted

How to handle component-based objects in a game loop?

Both approaches should result in the same result, so your choice really comes down to what makes the most sense architecturally. But first, your example for approach #2 is incorrect. Each system ...
congusbongus's user avatar
  • 14.9k
2 votes

Appropriate Cache Friendly Associative Container For An Entity Component System

ArcaneEngineer's advice is good, particularly for early development (to an extent - once you configure your engine to work a particular way, it can be significantly hard to rework it later). For ...
metamorphosis's user avatar
2 votes
Accepted

Where to store contiguous arrays of components?

The solution you described is using the so called "curiously recurring template pattern", often abbreviated as CRTP and is very common in C++ programming. This is a straightforward solution to the ...
LukeG's user avatar
  • 1,557
2 votes

Pass data down to components

Will you have networking? I understand that you are probably making a single player game engine. However, thinking about how to deal with the network very, very, very early in the desgin will push ...
Theraot's user avatar
  • 28k
2 votes

In Unreal Engine 4, how do I get the component's "game object" via C++?

Use GetOwner() in the component
Raildex's user avatar
  • 787
2 votes
Accepted

Where should I put units and items in a squad-combat ECS-based game?

As a general disclaimer and as DMGregory already stated it: The rules of ECS are not written in stone. Doing it on way has benefits, doing it another way has some others. So, you need to know, what ...
PSquall's user avatar
  • 1,332
2 votes

Component instance reference in Unreal Engine 4

To do this in Unreal C++, inside the CPP file you need to do the following: Make sure to include the header component: #include "Camera/CameraComponent.h" Then in the class constructor: ...
Stephen's user avatar
  • 1,040

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