Map Entities

When a map is loaded, its embedded entities are converted into GameObjects as children of the MapInstance's GameObject. The following entity types are handled automatically:

When a map is loaded, its embedded entities are converted into GameObjects as children of the MapInstance's GameObject. The following entity types are handled automatically:

Entity TypeWhat Gets Created
info_player_startSpawnPoint component
prop_dynamic / prop_animatedProp component (static)
prop_physicsProp component (networked)
func_brushModelRenderer + optional ModelCollider
env_sky2D Skybox
skybox_reference3D Skybox (MapSkybox3D)
env_gradient_fogGradientFog component
env_cubemap_fogCubemapFog component
env_cubemap / env_cubemap_boxEnvmapProbe component
env_volumetric_fog_volumeVolumetricFogVolume component
snd_soundscapeSoundscapeTrigger (sphere)
snd_soundscape_boxSoundscapeTrigger (box)
LightsSceneLight objects (directional, spot, omni, rect, capsule)

Any entity type not listed above will get a MapObjectComponent that manages its scene objects directly.

Custom Entity Handling

You can create your own MapInstance subclass and override OnCreateObject to handle custom entity types or modify how built-in types are created. This method is only called for entity types that are not already handled internally.

public class MyMapInstance : MapInstance
{
    protected override void OnCreateObject( GameObject go, MapLoader.ObjectEntry kv )
    {
        if ( kv.TypeName == "my_custom_entity" )
        {
            var myComponent = go.Components.Create<MyComponent>();
            myComponent.Health = kv.GetValue<float>( "health", 100 );
            myComponent.SpawnDelay = kv.GetValue<float>( "spawn_delay", 0 );
        }
    }
}

ObjectEntry

The ObjectEntry struct gives you access to all the entity's key-value data from Hammer.

kv.TypeName      // Entity class name, e.g. "prop_physics"
kv.TargetName    // The entity's target name
kv.ParentName    // The entity's parent name
kv.Position      // World position
kv.Angles        // Rotation angles
kv.Transform     // Full transform (position, rotation, scale)
kv.Tags          // Tags set in Hammer

You can read typed values, strings, and resource references from the entity's key-value pairs.

// Get a typed value with a default fallback
float health = kv.GetValue<float>( "health", 100 );
Color color = kv.GetValue<Color>( "rendercolor", Color.White );

// Get a string value
string message = kv.GetString( "message" );

// Get a resource reference
Model model = kv.GetResource<Model>( "model" );
Material mat = kv.GetResource<Material>( "material" );

Entity Parenting

Map entities that have a parentname set in Hammer will be parented to the corresponding entity's GameObject. Entities are sorted during load so that parents are created before their children.

Referenced API

Created at:
Updated at:

On this page