S&box Wiki

Linking Entities to Hammer

Linking Entities to Hammer

Entities defined in your addon will automatically generate an FGD and put it into your addons config folder.

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:

[Library("info_player_spawn", Description = "Spawn a player here")] public partial class SpawnPoint : Entity { }

Hammer Attributes

All of these are optional attributes that can be added to your class to change the behaviour in Hammer.

[Hammer.Solid]

Tells Hammer this entity is brush based.

[Hammer.Solid]

[Hammer.SupportsSolid]

Tells Hammer this point entity can also be a brush entity, such as ent_door entity.

[Hammer.SupportsSolid]

[Hammer.EditorModel]

Tells Hammer what model to use for the entity and is added to the class.

[Hammer.EditorModel( "models/editor/playerstart.vmdl" )]

[Hammer.EditorSprite]

Tells Hammer what model to use for the entity and is added to the class.

[Hammer.EditorSprite( "editor/info_target.vmat" )]

[Hammer.EntityTool]

Appends this Entity to Hammer's Entity tool list like so:

image.png
[Hammer.EntityTool( "Player Spawnpoint", "Player", "Defines a point where the player can (re)spawn" )]

[Hammer.Model]

Makes it so the model, skin and bodygroups can be set and changed in Hammer.

[Hammer.Model]

[Hammer.Skip]

Can be used if you do not want your entity exposed in Hammer.

[Hammer.Skip]

[Hammer.AutoApplyMaterial]

Automatically applies the supplied material to the tied brush.

[Hammer.AutoApplyMaterial( "materials/tools/toolstrigger.vmat" )]

Hammer Properties

Any property in your class can be exposed to Hammer using the [Property] attribute</page>.

An example of a property being defined:

public partial class MyEntity : Entity { /// <summary> /// Help text in hammer /// </summary> [Property( Title = "Start Disabled" ) ] public bool StartDisabled { get; set; } = false; }

Your entity properties will then show up in Hammer:

image.png

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:

public partial class MyEntity : Entity { /// <summary> /// Description of my input to be displayed in Hammer and in Visual Studio /// </summary> [Input] public void DoSomethingElse(string str) { } [Input( Name = "DoSomething" )] public void SomeInput() { } }

Outputs

Any output in your entity class is automatically exposed to Hammer as an output.

An example of an output being defined:

public partial class MyEntity : Entity { /// <summary> /// Description of my output to be displayed in Hammer and in Visual Studio /// </summary> public Output OnSomethingHappened; }

Firing Outputs

You can fire your output using Entity.FireOutput(name, sender) like this:

protected Output OnEndTouch { get; set; } public virtual void OnTouchEnd( Entity toucher ) { OnEndTouch.Fire( toucher ); }

Special Pages


Wikis

?

Render Time: 53ms

DB GetPage 37
Generate Html 3
SaveChanges (1) 9
Render Body 0
Render Sidebar 1