From 2a41366bd8b3b7354b0233b162426680fd32cfd9 Mon Sep 17 00:00:00 2001 From: copygirl Date: Sun, 19 Nov 2023 18:57:13 +0100 Subject: [PATCH] Have Entity.get return value instead of pointer --- src/entity.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 {