@@ -89,7 +89,7 @@ Here's how to create a new component:
89
89
90
90
``` gdscript
91
91
# c_bounce.gd
92
- class_name CBounce
92
+ class_name C_Bounce
93
93
extends Component
94
94
95
95
@export var normal := Vector2.ZERO
@@ -130,12 +130,12 @@ extends System
130
130
131
131
func query():
132
132
# All entities that all have transform, velocity and bounce components
133
- return q.with_all([CTransform, CVelocity, CBounce ])
133
+ return q.with_all([C_Transform, C_Velocity, C_Bounce ])
134
134
135
135
func process(entity: Entity, delta: float):
136
- var c_bounce: CBounce = entity.get_component(CBounce)
136
+ var c_bounce = entity.get_component(C_Bounce) as C_Bounce
137
137
if c_bounce.should_bounce:
138
- var c_velocity: CVelocity = entity.get_component(CVelocity)
138
+ var c_velocity = entity.get_component(C_Velocity) as C_Velocity
139
139
c_velocity.direction = c_bounce.normal
140
140
c_bounce.should_bounce = false
141
141
```
@@ -165,11 +165,11 @@ func _ready() -> void:
165
165
166
166
func _process(delta):
167
167
# Process only systems in the "gameplay" group
168
- ECS .process(delta, "gameplay")
168
+ world .process(delta, "gameplay")
169
169
170
170
func _physics_process(delta):
171
171
# Process only systems in the "physics" group
172
- ECS .process(delta, "physics")
172
+ world .process(delta, "physics")
173
173
```
174
174
175
175
## Example Project
@@ -183,7 +183,7 @@ To illustrate the usage of GECS, let's look at an example project that simulates
183
183
184
184
``` gdscript
185
185
# c_bounce.gd
186
- class_name CBounce
186
+ class_name C_Bounce
187
187
extends Component
188
188
189
189
@export var normal := Vector2.ZERO
@@ -194,7 +194,7 @@ extends Component
194
194
195
195
``` gdscript
196
196
# c_velocity.gd
197
- class_name CVelocity
197
+ class_name C_Velocity
198
198
extends Component
199
199
200
200
@export var direction := Vector2.ZERO
@@ -205,7 +205,7 @@ extends Component
205
205
206
206
``` gdscript
207
207
# c_transform.gd
208
- class_name CTransform
208
+ class_name C_Transform
209
209
extends Component
210
210
211
211
@export var transform: Transform2D
@@ -237,7 +237,7 @@ func on_ready() -> void:
237
237
Utils.sync_transform(self)
238
238
```
239
239
240
- Includes ` CPlayerMovement ` , ` CVelocity ` , ` CTransform ` , and ` CFriction ` components.
240
+ Includes ` C_PlayerMovement ` , ` C_Velocity ` , ` C_Transform ` , and ` C_Friction ` components.
241
241
242
242
### Systems
243
243
@@ -249,12 +249,12 @@ class_name BounceSystem
249
249
extends System
250
250
251
251
func query():
252
- return q.with_all([CTransform, CVelocity, CBounce ])
252
+ return q.with_all([C_Transform, C_Velocity, C_Bounce ])
253
253
254
254
func process(entity: Entity, delta: float):
255
- var c_bounce: CBounce = entity.get_component(CBounce)
255
+ var c_bounce = entity.get_component(C_Bounce) as C_Bounce
256
256
if c_bounce.should_bounce:
257
- var c_velocity: CVelocity = entity.get_component(CVelocity)
257
+ var c_velocity = entity.get_component(C_Velocity) as C_Velocity
258
258
c_velocity.direction = c_bounce.normal
259
259
c_bounce.should_bounce = false
260
260
```
@@ -267,11 +267,11 @@ class_name VelocitySystem
267
267
extends System
268
268
269
269
func query():
270
- return q.with_all([CVelocity, CTransform ])
270
+ return q.with_all([C_Velocity, C_Transform ])
271
271
272
272
func process(entity: Entity, delta: float):
273
- var c_velocity: CVelocity = entity.get_component(CVelocity)
274
- var c_transform: CTransform = entity.get_component(CTransform)
273
+ var c_velocity = entity.get_component(C_Velocity) as C_Velocity
274
+ var c_transform = entity.get_component(C_Transform) as C_Transform
275
275
var velocity_vector: Vector2 = c_velocity.direction.normalized() * c_velocity.speed
276
276
c_transform.transform.origin += velocity_vector * delta
277
277
```
@@ -284,7 +284,7 @@ class_name Transform2DSystem
284
284
extends System
285
285
286
286
func query():
287
- return q.with_all([CTransform ])
287
+ return q.with_all([C_Transform ])
288
288
289
289
func process(entity: Entity, delta):
290
290
Utils.sync_transform(entity)
316
316
** Example** :
317
317
318
318
``` gdscript
319
- var entities_with_velocity_and_not_captured = q.with_all([CVelocity ]).with_none([CCaptured ])
319
+ var entities_with_velocity_and_not_captured = q.with_all([C_Velocity ]).with_none([C_Captured ])
320
320
```
321
321
322
322
** Group Searching with Query Builder**
323
323
324
324
GECS supports filtering entities by Godot Group directly via the QueryBuilder. For example:
325
325
``` gdscript
326
- var entities = q.with_all([CVelocity ]).with_group("enemy")
326
+ var entities = q.with_all([C_Velocity ]).with_group("enemy")
327
327
```
328
328
This returns only entities with the specified components and that belong to the "enemy" group.
329
329
@@ -337,10 +337,10 @@ Systems have properties that allow for customizing their execution:
337
337
Example:
338
338
``` gdscript
339
339
func _physics_process(delta):
340
- ECS .process(delta, "physics")
340
+ world .process(delta, "physics")
341
341
342
342
func _process(delta):
343
- ECS .process(delta, "gameplay")
343
+ world .process(delta, "gameplay")
344
344
```
345
345
This will only process systems that are in the "physics" group in the physics process function and gameplay system in the _ process function
346
346
@@ -354,14 +354,6 @@ Systems can be assigned to specific groups, enabling you to control when and how
354
354
355
355
In your system script, set the ` group ` property to specify which group the system belongs to. These are not the same as godot groups.
356
356
357
- ** Import and Export World Functionality**
358
-
359
- GECS now allows you to save and load the entire world state. Use these methods:
360
- - ` ECS.export_world(file_path) ` to export the current world state.
361
- - ` ECS.import_world(file_path) ` to import a saved world state into the world. Optionally purge the world
362
-
363
- These functions facilitate state persistence and dynamic world loading.
364
-
365
357
### Pause Functionality
366
358
367
359
GECS systems inherit the regular Godot process modes, letting you choose whether they should run during pause.
0 commit comments