diff --git a/src/entity.zig b/src/entity.zig index 67a6cb2..37a6722 100644 --- a/src/entity.zig +++ b/src/entity.zig @@ -302,10 +302,13 @@ pub fn Entity(comptime ctx: anytype) type { } pub fn get(self: Self, comptime T: type) ?T { + return if (getRef(self, T)) |p| p.* else null; + } + + pub fn getRef(self: Self, comptime T: type) ?*const T { const id = Context.lookup(T).*; const ptr = c.ecs_get_id(self.world.raw, self.raw, id); - const typed_ptr: ?*const T = @alignCast(@ptrCast(ptr)); - return if (typed_ptr) |p| p.* else null; + return @alignCast(@ptrCast(ptr)); } pub fn getMut(self: Self, comptime T: type) ?*T {