Garry's Mod Wiki




Called when the entity is created. This is called when you Entity:Spawn the custom entity.

This is called after ENTITY:SetupDataTables and GM:OnEntityCreated.

This is sometimes not called clientside. You can work around this by setting a variable in Initialize and check if it exists in ENTITY:Think. See the example below.

Issue Tracker: 2732


Example Initialize function

function ENT:Initialize() -- Sets what model to use self:SetModel( "models/props/cs_assault/money.mdl" ) -- Sets what color to use self:SetColor( Color( 200, 255, 200 ) ) -- Physics stuff self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) -- Init physics only on server, so it doesn't mess up physgun beam if ( SERVER ) then self:PhysicsInit( SOLID_VPHYSICS ) end -- Make prop to fall on spawn local phys = self:GetPhysicsObject() if ( IsValid( phys ) ) then phys:Wake() end end


Fixes the function not being called clientside.

function ENT:Initialize() self.m_bInitialized = true -- Other code end function ENT:Think() if (not self.m_bInitialized) then self:Initialize() end -- Other code end

Page Links

Special Pages



Render Time: 37ms

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