Inspector Customization
This skill guides making components editable in the engine's editor UI using inspector tags.
Inspector Tags Reference
| Tag Format | Effect |
|---|---|
inspector:"Label" | Field shown with custom label |
inspector:"...,min:0,max:10" | Numeric range limits |
inspector:"...,step:0.1" | Slider step increment |
inspector:"...,type:vector3" | 3D vector editor |
inspector:"...,type:euler" | Euler angle editor |
inspector:"...,type:dropdown" | Dropdown selector |
inspector:"...,registry:mesh" | Mesh ID dropdown |
inspector:"...,registry:material" | Material ID dropdown |
inspector:"...,registry:shader" | Shader ID dropdown |
inspector:"...,type:layermask" | Collision layer mask |
| (no tag) | Field hidden from inspector |
json:"-" | Exclude from serialization |
Basic Tags
Simple Field
go
type MyComponent struct {
Speed float32 `inspector:"Movement Speed"`
}
With Range
go
type MyComponent struct {
Health float32 `inspector:"Health,min:0,max:100"`
Damage float32 `inspector:"Damage,min:0,max:1000,step:10"`
}
Boolean
go
type MyComponent struct {
IsActive bool `inspector:"Enabled"`
}
Numeric Types
Float32 with Step
go
Speed float32 `inspector:"Speed,min:0,max:100,step:0.5"`
Integer
go
Count int `inspector:"Count,min:0,max:100,step:1"`
Special Types
Vector3
go
Direction math.Vector3 `inspector:"Direction,type:vector3"` Offset math.Vector3 `inspector:"Offset,type:vector3"`
Euler Angles
go
Rotation math.Vector3 `inspector:"Rotation,type:euler"`
Dropdown
go
type EnemyState int
const (
StateIdle EnemyState = iota
StatePatrol
StateChase
StateAttack
)
State EnemyState `inspector:"State,type:dropdown,options:Idle|Patrol|Chase|Attack"`
Layer Mask
go
Layer int `inspector:"Collision Layer"` LayerMask int `inspector:"Layer Mask,type:layermask"`
Registry Dropdowns
go
MeshId string `inspector:"Mesh,registry:mesh"` MaterialId string `inspector:"Material,registry:material"` ShaderId string `inspector:"Shader,registry:shader"`
Complete Example
go
package component
import (
"github.com/TheLazyLemur/engine/math"
)
type EnemyData struct {
// Basic numeric
Health float32 `inspector:"Health,min:1,max:100,step:1"`
Speed float32 `inspector:"Speed,min:0.1,max:20,step:0.1"`
// State dropdown
State int `inspector:"State,type:dropdown,options:Idle|Patrol|Chase|Attack"`
// Vectors
PatrolPoint math.Vector3 `inspector:"Patrol Point,type:vector3"`
// References
TargetEntity uint64 `inspector:"Target Entity ID"`
// Boolean
IsAggressive bool `inspector:"Aggressive"`
// Hidden from inspector, runtime only
StateTimer float32 `json:"-"`
}
func NewEnemy() EnemyData {
return EnemyData{
Health: 50,
Speed: 5,
State: 0,
IsAggressive: false,
}
}
Hidden Fields
Use json:"-" to exclude from both serialization and inspector:
go
type TimerData struct {
Interval float32 `inspector:"Interval (sec),min:0.1,max:60"`
Elapsed float32 `json:"-"` // Runtime only
SpawnCount int `json:"-"` // Runtime only
}
Registration for Registry Dropdowns
For mesh/material/shader dropdowns to work, register them first:
go
func RegisterComponents(eng *engine.Engine) {
engine.RegisterComponent(eng, "MyComponent", MyComponent)
// Optional: provide available options
// The registry dropdowns auto-populate from loaded assets
}
Common Patterns
RGB Color
go
type ColoredData struct {
ColorR float32 `inspector:"Red,min:0,max:1,step:0.01"`
ColorG float32 `inspector:"Green,min:0,max:1,step:0.01"`
ColorB float32 `inspector:"Blue,min:0,max:1,step:0.01"`
}
Animation Timing
go
type AnimatedData struct {
FrameIndex int `inspector:"Frame"`
FrameCount int `inspector:"Total Frames,min:1,max:64"`
FrameDuration float32 `inspector:"Frame Duration,min:0.01,max:1"`
CurrentTime float32 `json:"-"`
}
Physics Properties
go
type PhysicsData struct {
Mass float32 `inspector:"Mass,min:0.1,max:100"`
Friction float32 `inspector:"Friction,min:0,max:1,step:0.01"`
Bounciness float32 `inspector:"Bounciness,min:0,max:1,step:0.01"`
}
Troubleshooting
Field not showing in inspector?
- •Check that component is registered:
engine.RegisterComponent(eng, "Name", ComponentType) - •Verify struct tag syntax is correct
- •Field must be exported (capital letter)
Dropdown is empty?
- •Mesh/material/shader must be loaded first
- •Check asset paths are correct
- •Registry populates from loaded assets, not files on disk
Numeric slider not working?
- •Ensure
min:,max:, andstep:are comma-separated - •Values must be valid numbers
See Also
- •engine-component: Creating component data structs
- •engine-scene: Using components in scenes
- •engine-system: Systems that read inspector values