Is there a way to check if an Entity still exists?
rgbDreamer
Join Date: 2011-10-02 Member: 125190Members
in Modding
<div class="IPBDescription">Attempt to access an object that no longer exists (was type Marine)</div>I've been getting a "Attempt to access an object that no longer exists (was type SquadUplink)" errors. Is there a way to check my reference to see if it still exists? The reference isn't nil and throws an error if I try to index it.
Also, is there a callback reliably called when an Entity stops "existing"? I've tried :OnDestroy(), but I might be doing something else wrong.
Thanks!
Also, is there a callback reliably called when an Entity stops "existing"? I've tried :OnDestroy(), but I might be doing something else wrong.
Thanks!
Comments
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> function Marine:OnEntityChange(oldEntityId, newEntityId)
Player.OnEntityChange(self, oldEntityId, newEntityId)
if(oldEntityId == self.UplinkId and not newEntityId) then
//handle uplink being destroyed
end
end<!--c2--></div><!--ec2-->
Yeah exactly, it returns a nil reference if it can't find a matching entity for that id. I also use that method, imho it's safer then working with a direct reference to a entity across update ticks.