diff --git a/game/systems_entity.c b/game/systems_entity.c index 994f947..69acafb 100644 --- a/game/systems_entity.c +++ b/game/systems_entity.c @@ -149,10 +149,7 @@ void entityFollowPath(ecs_iter_t *it) { Path *path = ecs_field(it, Path, 1); for (i32 i = 0; i < it->count; i++) { - ecs_entity_t entity = it->entities[i]; - - Path *entityPath = &path[i]; - TargetPosition target = entityPath->paths->waypoints[entityPath->curWaypoint]; + const ecs_entity_t entity = it->entities[i]; if (!ecs_has(ECS, entity, TargetPosition)) { if (path[i].curWaypoint >= path[i].paths->numWaypoints) { @@ -162,8 +159,12 @@ void entityFollowPath(ecs_iter_t *it) { path[i].paths = path[i].paths->next; if (!path[i].paths) ecs_remove(ECS, it->entities[i], Path); } - ecs_set_ptr(ECS, entity, TargetPosition, &target); - path[i].curWaypoint++; + if (path[i].paths) { + TargetPosition target = path[i].paths->waypoints[path[i].curWaypoint]; + path[i].curWaypoint++; + ecs_set_ptr(ECS, entity, TargetPosition, &target); + } + } } }