Problem destroying an entity I've created

As the title suggests, my entity...

	CreateCloakEntity = function(self)
		if myDebug then WARN('CreateCloakEntity') end
		ent = import('/lua/sim/Entity.lua').Entity({Owner = self,})
		ent:AttachBoneTo( -1, self, 'ura0206' )
		ent:SetMesh(self.MeshCloak)
		ent:SetDrawScale(self.MeshScale)
		ent:SetVizToFocusPlayer('Always')
		ent:SetVizToAllies('Always')
		ent:SetVizToNeutrals('Never')
		ent:SetVizToEnemies('Never')
		self.Trash:Add(ent)
	end,

Is created and attaches to the parent unit just fine. However later on when I need to dismiss the entity, I'm having problems removing it.

for k, v in self.CloakEntity do
	v:Destroy()
end

The "self.CloakEntity" is the Global table used to save the entity within the parent unit. Yet Destroy() neither flags an error nor removes the entity.

Any ideas or suggestions would be much apricated.

Side note: Looking inside of /lua/sim/Entity.lua I see that It's with a few basic functions that are mostly undefined / blank. Is it possible that's why the entity is not destroyed?

Resin

Got it !

	SetCloak = function(self, set)
		if myDebug then WARN('SetCloak: ', set) end
		local bp = self:GetBlueprint()
		if set and self.DoneBeingBuilt then
			if myDebug then WARN('	Delay before going active') end
			WaitTicks(self.CloakDelay or 1)
			if not self:IsDead()then
				if myDebug then WARN('	Cloak active') end
				self:HideBone('ura0206', false)
				if not self.CloakEntity then
					self:CreateCloakEntity()
				end
				self:EnableIntel('Cloak')
				self:EnableIntel('RadarStealth')
				self.CloakActive = true
			end
		else
			if myDebug then WARN('	Dropping cloak') end
			if self.CloakEntity then
				self.CloakEntity:Destroy()
				self.CloakEntity = nil
			end
			self:ShowBone('ura0206', false)
			self:DisableIntel('Cloak')
			self:DisableIntel('RadarStealth')
			self.CloakActive = false
		end
	end,

	CreateCloakEntity = function(self)
		if myDebug then WARN('CreateCloakEntity') end
		ent = import('/lua/sim/Entity.lua').Entity({Owner = self,})
		ent:AttachBoneTo( -1, self, 'ura0206' )
		ent:SetMesh(self.MeshCloak)
		ent:SetDrawScale(self.MeshScale)
		ent:SetVizToFocusPlayer('Always')
		ent:SetVizToAllies('Always')
		ent:SetVizToNeutrals('Never')
		ent:SetVizToEnemies('Never')
		self.CloakEntity = ent
		self.Trash:Add(ent)		
	end,

You forgot to do self.CloakEntity = ent in your original script 🙂

A work of art is never finished, merely abandoned

@jip Originally i was using...

self.CloakEntity = self:ForkThread(CreateCloakedEntity)

Uploaded V8 and it will include this unit... URA0206 Cybran Vampire