diff --git a/src/entity.zig b/src/entity.zig index 6771744..f0e4502 100644 --- a/src/entity.zig +++ b/src/entity.zig @@ -277,10 +277,11 @@ pub fn Entity(comptime ctx: anytype) type { c.ecs_remove_id(self.world.raw, self.raw, ecs_id); } - pub fn get(self: Self, comptime T: type) ?*const T { + pub fn get(self: Self, comptime T: type) ?T { const id = Lookup(ctx, T).id; const ptr = c.ecs_get_id(self.world.raw, self.raw, id); - return @alignCast(@ptrCast(ptr)); + const typed_ptr: ?*const T = @alignCast(@ptrCast(ptr)); + return if (typed_ptr) |p| p.* else null; } pub fn get_mut(self: Self, comptime T: type) ?*T {