Jump to content

stale component references on removed entities


Recommended Posts

So I guess it's a big no-no to try and get the world position of an entity that no longer exists.

 

I have a function in my custom component that runs on update. And this line of code has been giving me trouble:

local x, y, z = owner.Transform:GetWorldPosition()

It runs fine whenever "owner" exists.

except that "owner" can disappear at any time (it's supposed to do that, I promise). But even after the owner is removed, the code still runs anyways, crashing straight to desktop when it can't find the owner's world position.

The actual error printed out by the log is "Stale Component Reference"

 

I've tried a lot of different things to try and get it to ignore the code if the owner isn't there, but even checking for the owner seems to crash the game.

local x, y, z = nilif owner and owner.Transform:GetWorldPosition() then --THIS LINE CAUSES A CRASH FOR THE SAME REASON THE LINE BELOW IT DOES	x, y, z = owner.Transform:GetWorldPosition()end

apparently, just checking for "if owner then" doesn't work because the game still thinks it exists? Or something. I dunno.

 

and "if owner.Transform:GetWorldPosition() then" also crashes the game for "Stale Component Reference"

 

So I don't know how to get this function to check to make sure the owner exist before running that line of code. Does anyone have any ideas?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...