Check if entity exists

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
velocity
Senior Member
Posts: 220
Joined: Sat May 10, 2014 6:17 pm

Check if entity exists

Postby velocity » Mon Aug 13, 2018 6:31 am

I need to be available to check if Entity(index) exists, because the server crashes when I try to access an entity that doesn't exist anymore.

Also, is it possible to change what an entity is available to collide with through ContentMasks?

Syntax: Select all

is_in_solid(mask=<ContentMasks.ALL: 4294967295>, generator=<class '_entities.BaseEntityGenerator'>)
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Check if entity exists

Postby L'In20Cible » Mon Aug 13, 2018 3:03 pm

You should not store Entity instances unless you use a container designed to keep them up-to-date such as EntityDictionary. To validate whether or not an instance is still valid, you would have to loop through all existing entities and compare their address which can get quite slow if you validate them often. You could also try to use a conversion function and test for an exception but as stated above, keeping instances synced by listening the creation and deletion of the entities is definitely the fastest approach.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Check if entity exists

Postby Ayuto » Tue Aug 14, 2018 11:55 am

L'In20Cible wrote:To validate whether or not an instance is still valid, you would have to loop through all existing entities and compare their address [...]
I would like to add that this is not a recommended approach, because the entity could have been deleted and a new entity reuses the same memory address.

Like L'In20Cible metioned you should really use EntityDictionary or simply don't store the Entity instance.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 21 guests