Argonwolf Posted January 19, 2021 Share Posted January 19, 2021 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? Link to comment https://forums.kleientertainment.com/forums/topic/126247-how-do-you-check-if-a-prefab-still-exists/ Share on other sites More sharing options...
CarlZalph Posted January 19, 2021 Share Posted January 19, 2021 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. 1 Link to comment https://forums.kleientertainment.com/forums/topic/126247-how-do-you-check-if-a-prefab-still-exists/#findComment-1418123 Share on other sites More sharing options...
Argonwolf Posted January 19, 2021 Author Share Posted January 19, 2021 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. Link to comment https://forums.kleientertainment.com/forums/topic/126247-how-do-you-check-if-a-prefab-still-exists/#findComment-1418141 Share on other sites More sharing options...
Kleicher Posted January 19, 2021 Share Posted January 19, 2021 Nice and perfect Link to comment https://forums.kleientertainment.com/forums/topic/126247-how-do-you-check-if-a-prefab-still-exists/#findComment-1418159 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now