GamePlayKit — Entity/Components System
If you are here, maybe you are a game developer or some like apps developer with a lot of unfinished games, if not your case it’s mine…
GamePlayKit — Entity/Components System

If you are here, maybe you are a game developer or some like apps developer with a lot of unfinished games, if not your case it’s mine. And I hope this helps you finish your projects as it has helped me.
What is GameplayKit?
It’s a game framework developed by Apple, released in 2016. Come to help with classics topics like the architecture and organize your game logic.
What is Entity Components System?
Probably you hear about the discussion about “composition vs inheritance”.
Tl;dr, Entity Components System is a composition pattern purposed by Apple for videogames.
Think about this problem: You have a classic dungeon game where your hero tries to reach a princess or treasure, with a path filled with traps and monsters.
On a classic inheritance structure, you could have something like this:

When you go to create a new game object like a monster, for example, that could escalate badly, giving more responsibility to objects that shouldn’t.

And of course, you need to refactor code from your entities on a parent structure.
How Entity / Components solve this?
Two rules:
- Logic on components.
- No logic on entities.
Logic in Components 🤓
If your game logic is decoupled on small different components you can use and reuse to make new and different entities.
No logic on Entities 🧐
Of course, an entity has logic, but only compose logic, like “HeroEntity have this other 3 components with this particular values…”
Finally, for the previous example the objects diagram should look like this:

And this escalates efficiently, for example, if you want to create a new entity, such as the defense turret, you only need to compose a new entity, it seems simple and it is.

Now…
Code Time! 🤓
Let’s start with components, with a simple one:
GraphicComponent.swift
[embed]Example with SceneKit
This is super-atomic ones, but this depends on you, my recommendation is to make atomic components, that enlarge your scope of possibilities of different entities.
MovementComponent.swift
[embed]
As you can see, this component has more logic, but have only movement logic about how an entity will move.
Each component knows its entity, for that reason you can access to:
entity?.component(ofType: GraphicComponent.self)
This returns the unique GraphicComponent of the same entity or nil if they don’t have it.
Let continues with entities, remember, only compose logic as much as possible.
HeroEntity.swift
[embed]
Looks nice right? GKEntity persists a list of components. With this idea, you can compose and reuse every component, and get your code less messy.
I hope this serves as an introduction for GameplayKit, or support anyone with their game code.
What’s next?
GameplayKit Programming Guide:
Code examples:
메타데이터
- post_id
- d3c9c786f9d
- slug
- gameplaykit-entity-components-system-d3c9c786f9d
- url
- https://medium.com/@maetschl/gameplaykit-entity-components-system-d3c9c786f9d
- canonical_url
- https://medium.com/@maetschl/gameplaykit-entity-components-system-d3c9c786f9d
- author_url
- https://medium.com/@maetschl
- status
- ok
- fetched_at
- 2026-07-29 07:26:24