Beside shortening the code, you can also speed it up and make it more readable.
Syntax: Select all
from listeners import OnNetworkedEntityCreated
from weapons.manager import weapon_manager
from entities.constants import CollisionGroup
@OnNetworkedEntityCreated
def on_entity_created(entity):
if entity.classname in weapon_manager.projectiles:
entity.collision_group = CollisionGroup.DEBRIS_TRIGGER
m_CollisionGroup has been exported on the C++ side, which makes the access to the property much faster and more cross-game compatible in case the property is called differently in other games. It also forces the programmer to use the correct constants (CollisionGroup), which makes the code more readable. Moreover, we only need to apply the new collision group to certain projectiles. Those are always networked entities. So, we use the OnNetworkedEntityCreated listener and don't need to to the classname check for every entitiy.