ents.Create

From Garry's Mod
Jump to: navigation, search
 ents.Create( )

Contents

Description

Creates an entity. This function will fail and return NULL if the soft-edict limit is hit (8176), or the provided entity class doesn't exist.

WARNING

Do not use before GM:InitPostEntity has been called, otherwise the server will crash!
If you need to perform entity creation when the game starts, create a hook for GM:InitPostEntity and do it there

Arguments

string class

The classname of the entity to create

Returns

Entity

The created entity, or NULL if failed

Examples

Example

Creates a gmod_button entity near 0,0,0

local button = ents.Create( "gmod_button" )
if ( !IsValid( button ) ) then return end // Check whether we successfully made an entity, if not - bail
button:SetModel( "models/dav0r/buttons/button.mdl" )
button:SetPos( Vector( 0, 0, 100 ) )
button:Spawn()


Personal tools
Navigation