Jump to content

Recommended Posts

In my mod I require the ability for players to create and link wormholes. I've got it working fine, but players can also destroy wormholes that were player-built. The problem is, a player can link a wormhole that's been destroyed to an existing one. If someone jumps in, it crashes the game because the wormhole no longer exists. However, when I check that the prefab is not equal to nil, it always comes back true even if it has been deleted. I tried getting the prefab of an object that's already been deleted, and it returns the correct prefab.

How can I check if something exists? I'd have thought its values in memory would be manually deleted by the game engine, but it seems they're left for garbage collection, which won't remove them since I still have references to that object in my mod that aren't components of the prefab and therefore don't get automatically deleted when the wormhole does. Is there a method that returns whether a prefab exists or not?

Using this will return false if an entity no longer exists: entref:IsValid()

The stored reference to the entity will still be to the entity's table despite it no longer existing.

 

Note that when you serialize saving the links you should also be saving by an entity GUID like you can see with the teleporter component's targetTeleporter saving mechanism.

  • Like 1
2 hours ago, CarlZalph said:

Using this will return false if an entity no longer exists: entref:IsValid()

The stored reference to the entity will still be to the entity's table despite it no longer existing.

 

Note that when you serialize saving the links you should also be saving by an entity GUID like you can see with the teleporter component's targetTeleporter saving mechanism.

Perfect, thank you. I already have code that when a wormhole is destroyed, it removes the target wormhole's target so it can't be used and crash the game.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...