Revision Difference
Linking_Entities_to_Hammer#544219
<cat>Code.Game</cat>
<title>Linking Entities to Hammer</title>
Entities defined in your addon will automatically generate an [FGD](https://developer.valvesoftware.com/wiki/FGD) and put it into your addons `config` folder.
⤶
## Creating an entity
⤶
Create a partial class and make it inherit from <page text="Entity">Sandbox.Entity</page> - <page text="ModelEntity">Sandbox.ModelEntity</page>, <page text="AnimEntity">Sandbox.AnimEntity</page>, etc.. derive from this too.
⤶
To link this entity to Hammer you need to add a <page text="[Library] Attribute">Sandbox.LibraryAttribute</page> to your class, this will define the entity name and description.⤶
A basic example:⤶
⤶
# Creating an entity
⤶
To link your entity to Hammer you need to add a [Library] attribute to your class, this will define the entity name and description.
⤶
A basic example:⤶
```csharp
[Library("info_player_spawn", Description = "It indicates the position and facing direction at which the player will spawn.")]
[Library("info_player_spawn", Description = "Spawn a player here")]
public partial class SpawnPoint : Entity
{
}
```
⤶
## Optional class attributes⤶
⤶
# Hammer Attributes⤶
All of these are optional attributes that can be added to your class to change the behaviour in Hammer.
⤶
### [Hammer.Solid]
⤶
<page text="[Hammer.Solid]">Hammer.SolidAttribute</page> tells Hammer this entity is brush based.
⤶
## [Hammer.Solid]
⤶
Tells Hammer this entity is brush based.
```csharp
[Hammer.Solid]
```
⤶
### [Hammer.EditorModel]
⤶
<page text="[Hammer.EditorModel]">Hammer.EditorModelAttribute</page> tells Hammer what model to use for the entity and is added to the class.
⤶
## [Hammer.EditorModel]
⤶
Tells Hammer what model to use for the entity and is added to the class.
```csharp
[Hammer.EditorModel( "models/editor/playerstart.vmdl" )]
```
⤶
### [Hammer.EditorSprite]
⤶
<page text="[Hammer.EditorSprite]">Hammer.EditorSpriteAttribute</page> tells Hammer what model to use for the entity and is added to the class.
⤶
## [Hammer.EditorSprite]
⤶
Tells Hammer what model to use for the entity and is added to the class.
```csharp
[Hammer.EditorSprite( "editor/info_target.vmat" )]
```
⤶
### [Hammer.EntityTool]
⤶
<page text="[Hammer.EntityTool]">Hammer.EntityToolAttribute</page> appends this Entity to Hammer's Entity tool list like so:
⤶
## [Hammer.EntityTool]
⤶
Appends this Entity to Hammer's Entity tool list like so:
<upload src="a5727/8d92f33819330cb.png" size="4947" name="image.png" />
```csharp
[Hammer.EntityTool( "Player Spawnpoint", "Player", "Defines a point where the player can (re)spawn" )]
```
⤶
### [Hammer.Model]
⤶
<page text="[Hammer.Model]">Hammer.ModelAttribute</page> makes it so the model, skin and bodygroups can be set and changed in Hammer.
⤶
## [Hammer.Model]
⤶
Makes it so the model, skin and bodygroups can be set and changed in Hammer.
```csharp
[Hammer.Model]
```
⤶
### [Hammer.Skip]
⤶
<page text="[Hammer.Skip]">Hammer.SkipAttribute</page> can be used if you do not want your entity exposed in Hammer.
⤶
## [Hammer.Skip]
⤶
Can be used if you do not want your entity exposed in Hammer.
```csharp
[Hammer.Skip]
```
⤶
## Exposing properties to Hammer⤶
Any property in your class can be exposed to Hammer using the <page text="[Property] attribute">Sandbox.PropertyAttribute</page>.
⤶
# Hammer Properties⤶
Any property in your class can be exposed to Hammer using the [Property] attribute</page>.
An example of a property being defined:
```csharp
public partial class MyEntity : Entity
{
[Property( Name = "variable_name", Title = "Variable Title", Help = "Help text for variable" )]
[Sandbox.Internal.DefaultValue( "Default Value" )]⤶
public string MyVariable { get; set; } = "Default Value";⤶
[Property( Title = "Start Disabled" ) ]
public bool StartDisabled { get; set; } = false;⤶
}
```
⤶
<note>Sandbox.Internal.DefaultValue is in the internal namespace so behavior could change.</note>⤶
Your entity properties will then show up in Hammer:
<upload src="a5727/8d92f36d98ce869.png" size="11599" name="image.png" />
⤶
Supported property types:⤶
⤶
* int⤶
* float⤶
* bool⤶
* Vector3⤶
* string⤶
* Rotation⤶
* Angles⤶
* SoundEvent⤶
* Material⤶
⤶
## Inputs⤶
⤶
Any method in your entity class can be exposed to Hammer as an input using the <page text="[Input] attribute">Sandbox.InputAttribute</page> - parameters you define are automatically handled.⤶
⤶
# Inputs⤶
⤶
Any method in your entity class can be exposed to Hammer as an input using the [Input] attribute - parameters you define are automatically handled.⤶
An example of an input being defined:
```csharp
public partial class MyEntity : Entity
{
[Input]
public void DoSomethingElse(string str)
{
}
[Input( Name = "DoSomething", Help = "Help text for input" )]
public void SomeInput()
{
}
}
```
⤶
## Outputs
Any <page text="Output">Sandbox.Output</page> in your entity class is automatically exposed to Hammer as an output.
⤶
# Outputs
Any output in your entity class is automatically exposed to Hammer as an output.
An example of an output being defined:
```csharp
public partial class MyEntity : Entity
{
[Sandbox.Internal.Description( "Fires when something happens" )]⤶
public Output OnSomethingHappened;
}
```
⤶
### Firing Outputs
⤶
# Firing Outputs
You can fire your output using `Entity.FireOutput(name, sender)` like this:
```csharp
public static void MakeItDoSomething(SomeEntity ent)
protected Output OnEndTouch { get; set; }
⤶
public virtual void OnTouchEnd( Entity toucher )⤶
{
ent.FireOutput("OnSomethingHappened", null);
OnEndTouch.Fire( toucher );
}
```
⤶
<validate>Are additional FireOutput codegenned from the Output properties?</validate>