Garry's Mod Wiki

GM:EntityRemoved

  GM:EntityRemoved( Entity ent, boolean fullUpdate )

Description

Called right before removal of an entity.

This hook is called clientside during full updates due to how networking works in the Source Engine.

This can happen when the client briefly loses connection to the server, and can be simulated via cl_fullupdate for testing purposes.

Arguments

1 Entity ent
Entity being removed
2 boolean fullUpdate
Whether the removal is happening due to a full update clientside.

The entity may or may not be recreated immediately after, depending on whether it is in the local player's PVS. (See Entity:IsDormant)

Example

Adds all sent_ball's into a list, which is cleared when they are removed.

local BallList = {} hook.Add( "OnEntityCreated", "BallList", function( ent ) if ( not ent:IsValid() or not ent:GetClass() == "sent_ball" ) then return end BallList[ ent:EntIndex() ] = ent end ) hook.Add( "EntityRemoved", "ClearBallList", function( ent, fullUpdate ) if ( fullUpdate ) then return end BallList[ ent:EntIndex() ] = nil end )