Skip to content

Commit 7e432ca

Browse files
committed
[Patch] fixed the "no entity found" issue
1 parent 9c4b37e commit 7e432ca

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

Sources/UntoldEngine/ECS/Scenes.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public struct Scene {
1818
public mutating func remove<T: Component>(component _: T.Type, from entityId: EntityID) {
1919
let entityIndex = getEntityIndex(entityId)
2020
guard entities[Int(entityIndex)].entityId == entityId else {
21-
handleError(.entityMissing)
21+
handleError(.entityMissing, entityId)
2222
return
2323
}
2424

@@ -29,7 +29,7 @@ public struct Scene {
2929
public mutating func destroyEntity(_ entityId: EntityID) {
3030
let entityIndex = getEntityIndex(entityId)
3131
guard entities[Int(entityIndex)].entityId == entityId else {
32-
handleError(.entityMissing)
32+
handleError(.entityMissing, entityId)
3333
return
3434
}
3535
let newId = createEntityId(EntityIndex(UInt32.max), getEntityVersion(entityId))
@@ -59,7 +59,7 @@ public struct Scene {
5959
let entityIndex = getEntityIndex(entityId)
6060

6161
guard entities[Int(entityIndex)].entityId == entityId else {
62-
handleError(.entityMissing)
62+
handleError(.entityMissing, entityId)
6363
return nil
6464
}
6565

@@ -99,7 +99,7 @@ public struct Scene {
9999
}
100100

101101
guard entities[Int(entityIndex)].entityId == entityId else {
102-
handleError(.entityMissing)
102+
handleError(.entityMissing, entityId)
103103
return nil
104104
}
105105

Sources/UntoldEngine/Editor/EditorView.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,9 @@ public struct EditorView: View {
112112

113113
private func editor_clearScene() {
114114
destroyAllEntities()
115+
removeGizmo()
115116
EditorComponentsState.shared.clear()
116117

117-
let gameCamera = createEntity()
118-
setEntityName(entityId: gameCamera, name: "Main Camera")
119-
createGameCamera(entityId: gameCamera)
120-
121118
let light = createEntity()
122119
setEntityName(entityId: light, name: "Directional Light")
123120
createDirLight(entityId: light)

Sources/UntoldEngine/Systems/RegistrationSystem.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ public func destroyEntity(entityId: EntityID) {
3939
}
4040

4141
public func destroyAllEntities() {
42-
for entity in scene.getAllEntities() {
43-
// scene camera should not be destroyed
44-
if hasComponent(entityId: entity, componentType: SceneCameraComponent.self) {
45-
continue
46-
}
42+
// Take a snapshot so iteration isn't affected by mutations
43+
// Note, we only get parents.
44+
let toDestroy = getEntitiesWithLevel(level: 0).filter {
45+
!hasComponent(entityId: $0, componentType: SceneCameraComponent.self)
46+
}
4747

48+
for entity in toDestroy {
4849
destroyEntity(entityId: entity)
49-
globalEntityCounter = 0
5050
}
51+
52+
globalEntityCounter = 0
5153
}
5254

5355
private func setEntityMeshCommon(

0 commit comments

Comments
 (0)