From 802139205c95608e1781a898dff5aed2d9756ad2 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 24 Nov 2024 21:54:05 +0100 Subject: [PATCH] Update Unit.lua - Fixed bug in `UNIT:GetDCSObject()` when DCS unit does not exist. --- Moose Development/Moose/Wrapper/Unit.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Moose Development/Moose/Wrapper/Unit.lua b/Moose Development/Moose/Wrapper/Unit.lua index d282ff859..c0531e14c 100644 --- a/Moose Development/Moose/Wrapper/Unit.lua +++ b/Moose Development/Moose/Wrapper/Unit.lua @@ -240,7 +240,9 @@ end -- @return DCS#Unit The DCS Group. function UNIT:GetDCSObject() - if (not self.LastCallDCSObject) or (self.LastCallDCSObject and timer.getTime() - self.LastCallDCSObject > 1) then + -- FF: Added checks that DCSObject exists because otherwise there were problems when respawning the unit right after it was initially spawned (e.g. teleport in OPSGROUP). + -- Got "Unit does not exit" after coalition.addGroup() when trying to access unit data because LastCallDCSObject<=1. + if (not self.LastCallDCSObject) or (self.LastCallDCSObject and timer.getTime()-self.LastCallDCSObject>1) or (self.DCSObject==nil) or (self.DCSObject:isExist()==false) then -- Get DCS group. local DCSUnit = Unit.getByName( self.UnitName )