12 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
  • 26.6k
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 ...
Sean Middleditch's user avatar
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,178
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
  • 134k
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,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 ...
DMGregory's user avatar
  • 134k
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 ...
Theraot's user avatar
  • 26.6k
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
6 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
  • 134k
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
  • 29.5k
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 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 ...
Vaillancourt's user avatar
  • 16.3k
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,763
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
  • 119k
3 votes
Accepted

How to disable script component while in game?

Assume that you have a script like so: ...
John Hamilton's user avatar
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
  • 29.5k
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
  • 119k
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

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,759
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.3k
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
  • 134k
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
  • 119k
2 votes
Accepted

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

I have spent some time working with ECS-like approaches and can now write the conclusion. Making complex queries for your entities is alright (and necessary) as long as they are not a bottleneck (...
interphx's user avatar
  • 395
2 votes

Issue with Button component

In the top of the window where you see that, you should see a tab named 'Debug'. Normally the tab would be named 'Inspector'. The difference is that at some point you clicked the little menu drop down ...
Chris Mills-Price's user avatar
2 votes

AI: dealing with movement driving the same inputs as the player

Several possible solutions; one or a combination may be right for you. Steering Behavior Basically, in this case, that means that you AI needs to slow down as it approaches the target location. This ...
Sean Middleditch's user avatar
2 votes

How to disable script component while in game?

The only thing you need to change in that script is the call to GetComponent. Change <Light> to the name of the class ...
Philipp's user avatar
  • 119k

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