Garry's Mod Wiki


GM:OnEntityCreated( Entity entity )


Called when the entity is created.

Some entities on initial map spawn are passed through this hook, and then removed in the same frame. This is used by the engine to precache things like models and sounds, so always check their validity with IsValid.
Removing the created entity during this event can lead to unexpected problems. Use timer.Simple( 0, .... ) to safely remove the entity.


1 Entity entity
The entity


When a prop spawns it yells.

hook.Add( "OnEntityCreated", "PropScream", function( ent ) if ( ent:GetClass() == "prop_physics" ) then ent:EmitSound( "vo/npc/male01/no02.wav" ) end end )


Adds all props and ragdolls into a list. More efficient alternative to looping over ents.GetAll.

local TrackedEnts = { [ "prop_physics" ] = true, [ "prop_ragdoll" ] = true } local EntList = {} hook.Add( "OnEntityCreated", "SoftEntList", function( ent ) if ( not ent:IsValid() or not TrackedEnts[ ent:GetClass() ] ) then return end EntList[ ent:EntIndex() ] = ent end )

Page Links

Special Pages



Render Time: 66ms

DB GetPage 40
Generate Html 4
SaveChanges (1) 8
Render Body 0
Render Sidebar 12