diff --git a/tpl/macro.twig b/tpl/macro.twig index 87f4faa..d0ae71c 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -784,6 +784,7 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack var dv = bhl.Val.New(frm.vm); dv._obj = e.GetInternalWorld(); dv._num = e.GetInternalId(); + dv._num2 = e.GetInternalGen(); dv.type = cl; stack.Push(dv); @@ -907,9 +908,10 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld) { #if !BHL_FRONT - var pool = ((Leopotam.Ecs.EcsWorld)ctx.obj).GetPool(); - int idx = (int)ctx._num; - ref var f = ref pool.GetItem(idx); + var ent = ((EcsWorld)ctx._obj).RestoreEntityFromInternalId((int)ctx._num, (int)ctx._num2); + if(!ent.IsAlive() || !ent.Has()) + throw new System.Exception("Component '{{o.name}}' is no longer valid"); + ref var f = ref ent.Ensure(); {{ _self.native2val(f.type, 'f.' ~ f.name, 'v') }}; #endif @@ -925,9 +927,10 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld) { #if !BHL_FRONT - var pool = ((Leopotam.Ecs.EcsWorld)ctx.obj).GetPool(); - int idx = (int)ctx._num; - ref var f = ref pool.GetItem(idx); + var ent = ((EcsWorld)ctx._obj).RestoreEntityFromInternalId((int)ctx._num, (int)ctx._num2); + if(!ent.IsAlive() || !ent.Has()) + throw new System.Exception("Component '{{o.name}}' is no longer valid"); + ref var f = ref ent.Ensure(); {{ _self.val2native(f.type, 'v', 'f.' ~ f.name) }}; #endif