S&box Wiki

Map Placeable Entities

image.png

Entities can be placed through the Entity Tool, as with everything else in s&box they are automatically hotloaded within your game and Hammer.

If your game is published on s&works people can place entities for your game without even needing to download it.

Creating an entity

Creating entities that can be placed in Hammer is as simple as marking them with [HammerEntity].

using Sandbox; using SandboxEditor; /// <summary> /// This entity defines the spawn point of the player in first person shooter gamemodes. /// </summary> [Library( "info_player_start" ), HammerEntity] [Title( "Player Spawnpoint" ), Category( "Player" ), Icon( "place" )] public class SpawnPoint : Entity { }

Properties

image.png

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

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

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 Output.Fire(sender) like this:

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

Hammer Attributes

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

[Solid]

Tells Hammer this entity is brush based.

[Solid]

[SupportsSolid]

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

[SupportsSolid]

[EditorModel]

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

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

[EditorSprite]

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

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

[Model]

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

[Model]

[AutoApplyMaterial]

Automatically applies the supplied material to the tied brush.

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