Editable Entities

From Garry's Mod
Jump to: navigation, search

Making an entity editable is a lot easier than you would think. To edit an entity in realtime in sandbox mode (or your own gamemode if you have it enabled), you simply hold C (context menu) and right click on the entity. A submenu appears, and choosing properties will show a window like the one below.

entity editor example.jpg


Mark it as editable

The first thing to do is to mark it as editable.

ENT.Editable = true

Simple enough?

Data Tables

The rest of the magic happens in ENT:SetupDataTables - where you're hopefully already defining your network variables for you entity. It probably looks something like this right now.

function ENT:SetupDataTables()

	self:NetworkVar( "Float",	0, "FogStart" )
	self:NetworkVar( "Float",	1, "FogEnd" )
	self:NetworkVar( "Float",	2, "Density" )
	self:NetworkVar( "Vector",	0, "FogColor" )


So all you need to do is add options to the end of each of these.

function ENT:SetupDataTables()

	self:NetworkVar( "Float",	0, "FogStart",	{ KeyName = "fogstart",	Edit = { type = "Float",		order = 1, min = 0, max = 1000000 } } )
	self:NetworkVar( "Float",	1, "FogEnd",	{ KeyName = "fogend",	Edit = { type = "Float",		order = 2, min = 0, max = 1000000 } } )
	self:NetworkVar( "Float",	2, "Density",	{ KeyName = "density",	Edit = { type = "Float",		order = 3, min = 0, max = 1 } } )
	self:NetworkVar( "Vector",	0, "FogColor",	{ KeyName = "fogcolor",	Edit = { type = "VectorColor",	order = 4 } } )


This might seem a bit complicated, but it's simple really.

We have a table with:


This defines the key-value name of this variable. This is the standard way in Source to handle networked entity variables, and is required for editing to work. As a bonus, it will also allow map-makers to create maps containing your entity and set these variables.


This is a subtable describing how to edit this variable. The actual contents of this table differs with each type of variable, and are described below.


These variables are shared between all "edit types":

  • title - a string - the title to show to the left of the control. If unset it will default to the control name. This must be unique to each item.
  • order - a number - will display the lowest orders first.
  • category - a string - controls are grouped by category (defaults to "Main")


A simple text box.

  • waitforenter - boolean, whether the value should be updated in real-time as the user types, or only when they press enter. (default: false)


This type is a simple checkbox. There's no other settings in here apart from the shared values.


This provides the client with a number slider.

  • min - The minimum value (defaults to 0)
  • max - The maximum value (defaults to 1)


Identical to Float but only lets you choose integers.


This provides the client with a colour selector - which is represented by a Vector. Each colour's range is between 0-1.


This is a ComboBox.

  • text = the default selection. (default: "Select...")
  • values = a key/value table of available options in the ComboBox. Keys are the identifier string, values are the associated actual values. Required.


The property editors are modular, and are defined in lua/vgui/ - each starting with prop_*.

Creating your own should be quite simple by looking at these files.

Personal tools