> defold-proto-file-editing
Creates and edits Defold resource and component files that use Protobuf Text Format (.collection, .go, .atlas, .sprite, .gui, .collisionobject, .convexshape, .label, .font, .material, .model, .mesh, .particlefx, .sound, .camera, .factory, .collectionfactory, .collectionproxy, .tilemap, .tilesource, .objectinterpolation). Use when asked to create, modify, or configure any Defold proto text format file.
curl "https://skillshub.wtf/indiesoftby/defold-agent-config/defold-proto-file-editing?format=md"Editing Defold Proto Text Format Files
Creates and edits Defold resource and component files that use Protobuf Text Format.
When to use
This skill covers all Defold file types that are serialized as Protobuf Text Format. It does NOT cover Lua script files (.script, .gui_script, .render_script, .editor_script).
Supported file types
For detailed field references, consult the per-type reference file in references/:
references/collection.md—.collectionfiles (game levels, hierarchies)references/gameobject.md—.gofiles (game object prototypes)references/gui.md—.guifiles (GUI scenes)references/atlas.md—.atlasfiles (texture atlases)references/sprite.md—.spritefiles (sprite components)references/collisionobject.md—.collisionobjectfiles (physics)references/convexshape.md—.convexshapefiles (external convex hull collision shapes)references/label.md—.labelfiles (text in game space)references/font.md—.fontfiles (font resources)references/material.md—.materialfiles (render materials)references/model.md—.modelfiles (3D models)references/mesh.md—.meshfiles (custom 3D meshes from buffer data)references/particlefx.md—.particlefxfiles (particle effects)references/sound.md—.soundfiles (audio)references/camera.md—.camerafiles (camera components)references/factory.md—.factoryfiles (object spawning)references/collectionfactory.md—.collectionfactoryfiles (collection spawning)references/collectionproxy.md—.collectionproxyfiles (world loading)references/tilemap.md—.tilemapfiles (tile grids)references/tilesource.md—.tilesourcefiles (tile source resources)references/objectinterpolation.md—.objectinterpolationfiles (extension: interpolation of fixed step movement)
For skill maintenance tasks (updating references, fetching proto schemas), use the defold-skill-maintain skill.
Shaders and materials relationship
Shaders (.vp, .fp, .glsl) are GLSL files and are NOT covered by this skill — use the defold-shaders-editing skill for shader files. However, shaders and materials are tightly coupled:
Data flow from material to shader
-
Constants declared in
vertex_constants/fragment_constantsbecomeuniformvariables in shaders. Engine-provided constants (CONSTANT_TYPE_VIEW,CONSTANT_TYPE_PROJECTION, etc.) are automatically populated. User constants (CONSTANT_TYPE_USER) can be animated viago.set()/go.animate(). -
Samplers declared in
samplersbecomesampler2Duniforms. The samplernamein the material must match the uniform name in the shader. -
Attributes declared in
attributesbecome vertexinvariables. Semantic types likeSEMANTIC_TYPE_POSITION,SEMANTIC_TYPE_TEXCOORDprovide engine-generated data.
Instancing with mtx_world and mtx_normal
For instanced rendering, two special vertex attributes are available without declaring them in the material's attributes section:
mtx_world—mat4world transformation matrix (per-instance)mtx_normal—mat4normal transformation matrix (per-instance)
When these are declared as vertex in attributes in the shader, Defold automatically enables instanced rendering:
// model_instanced.vp
in mediump mat4 mtx_world;
in mediump mat4 mtx_normal;
void main() {
vec4 p = mtx_view * mtx_world * vec4(position.xyz, 1.0);
var_normal = normalize((mtx_normal * vec4(normal, 0.0)).xyz);
gl_Position = mtx_proj * p;
}
Requirements for instancing:
- Material must have
vertex_space: VERTEX_SPACE_LOCAL - Shader declares
mtx_worldand/ormtx_normalasinattributes - No need to add these to the material's
attributeslist
Reference examples
Built-in shader examples are in .deps/builtins/materials/:
sprite.vp/sprite.fp— 2D sprite rendering (world space)model.vp/model.fp— 3D model rendering (local space, uniforms)model_instanced.vp— 3D model with instancing (usesmtx_world,mtx_normalas attributes)
Bundled scripts
scripts/get_image_size.py— Get image dimensions (width × height) from PNG/JPEG files. Pure Python, no external dependencies. Use this when creating collision object box shapes that should match sprite image sizes. Seereferences/collisionobject.md→ "Sizing box shapes from sprite images" for the full workflow.scripts/gen_convexshape.py— Generate a.convexshapefile from a 2D image's non-transparent silhouette. Uses PIL/Pillow. Computes a convex hull, simplifies to ≤16 points (Box2D limit), centers at origin, and outputs Defold.convexshapeformat. Seereferences/convexshape.md→ "Generating from an image" for usage.scripts/gen_silhouette_chain.py— Generate a.collisionobjectfile with a chain of rotated TYPE_BOX shapes tracing the contour of any image silhouette (concave, with holes, multi-part). Uses PIL/Pillow. Extracts boundary contour loops, simplifies with RDP, and outputs a.collisionobjectwith thin rotated boxes along each edge. Seereferences/collisionobject.md→ "Silhouette chain from image contour" for usage.
Embedded component type names
When embedding components in .go or .collection files, these are the type string values:
"sprite"— Sprite component"label"— Label component"collisionobject"— Collision object"sound"— Sound component"particlefx"— Particle effect"model"— 3D model"mesh"— Mesh"camera"— Camera"factory"— Factory"collectionfactory"— Collection factory"collectionproxy"— Collection proxy"tilegrid"— Tilemap (note: type is"tilegrid", not"tilemap")"objectinterpolation"— Object interpolation (extension)
GUI components (.gui) CANNOT be embedded inline — they must be added as referenced components.
Protobuf Text Format rules
These rules apply to ALL Defold proto text format files:
- Default omission: Omit fields that equal their proto default. This keeps files minimal and matches Defold editor output.
- Message blocks: Use
field_name { ... }with nestedkey: valuepairs. - Floats: Always include decimal point:
1.0, not1. - Integers: No decimal point:
4, not4.0. - Strings: Always double-quoted:
"text". - Enums: Use the constant name without quotes:
BLEND_MODE_ALPHA. - Booleans:
trueorfalse, no quotes. - Repeated fields: Each scalar value gets its own line with the field name.
- Repeated messages: Each entry gets its own
field_name { ... }block. - Field order: Follow the proto field number order.
- No trailing commas or semicolons.
- Indentation: 2 spaces per nesting level inside message blocks.
- Newlines: One empty line between the end of a message block
}and the next field. No empty line between consecutive scalar fields. - No blank lines between fields or blocks within the same nesting level (match Defold editor output).
Vector and math type conventions
These types from ddf_math.proto appear across many file types:
dmMath.Vector3 / dmMath.Point3
Components: x, y, z (and d, rarely used). All default to 0.0.
dmMath.Vector3One
Components: x, y, z (and d, rarely used). All default to 1.0.
dmMath.Vector4
Components: x, y, z, w. All default to 0.0.
dmMath.Vector4One
Components: x, y, z, w. All default to 1.0.
dmMath.Vector4WOne
Components: x, y, z, w. x/y/z default to 0.0, w defaults to 1.0.
dmMath.Quat
Components: x, y, z, w. x/y/z default to 0.0, w defaults to 1.0.
Omission rules for vector/math blocks
- Only include components that differ from their default value.
- If all components are at defaults, omit the entire block (for optional fields).
- If the field is required, include the block but leave it empty:
position { }.
position {
x: 200.0
y: 100.0
}
rotation {
z: 0.7071068
w: 0.7071068
}
Data string encoding rules
Game objects embedded in .collection files and components embedded in .go files encode their content as multi-line strings in a data field.
Single nesting level (game object with referenced components)
The content is escaped once:
- Quotes become
\" - Newlines become
\n
data: "components {\n"
" id: \"script\"\n"
" component: \"/main/main.script\"\n"
"}\n"
""
Double nesting level (game object with embedded components)
The embedded component's data field requires double escaping:
- Outer quotes:
\" - Inner quotes (inside component data):
\\\" - Outer newlines:
\n - Inner newlines (inside component data):
\\n
data: "embedded_components {\n"
" id: \"camera\"\n"
" type: \"camera\"\n"
" data: \"aspect_ratio: 1.0\\n"
"fov: 0.7854\\n"
"near_z: -1.0\\n"
"far_z: 1.0\\n"
"orthographic_projection: 1\\n"
"\"\n"
"}\n"
""
Common mistake — closing quote of inner data: The line that closes the inner data string (the \" that ends the embedded component's data value) must use single-escaped newline "\"\n", NOT double-escaped "\"\\n". The closing quote \" is the boundary between nesting levels — after it, you are back at the outer (game object) level, so the newline is single \n. Using \\n here corrupts the game object data and causes a load error.
Note: After the opening data: \"...\\n" line inside double-nested data, subsequent lines of that inner data do NOT have leading whitespace (they start at column 0 of the quoted string).
Multi-line string concatenation blocks end with an empty "" terminator. A single-line data: "" does not need an additional terminator.
Workflow
Creating a new file
- Determine the file type and path.
- Consult the relevant reference file in
references/for the field structure. - Set all required fields.
- Set optional fields only if they differ from defaults.
- Follow proto field number order.
- Apply all Protobuf Text Format rules above.
Editing an existing file
- Read the current file.
- Modify only the requested fields.
- Preserve existing field values and order.
- Apply omission rules: remove fields that become equal to their defaults after editing.
- When editing existing files, preserve the existing formatting style.
> related_skills --same-repo
> xmath-usage
Provides xmath API reference and in-place math optimization patterns for Defold. Use when writing performance-critical math code, optimizing vector/quaternion/matrix operations, or when the user mentions xmath, zero-allocation math, or reducing Lua GC pressure.
> monarch-screen-setup
Organizes screens and popups in a Defold game using Monarch screen manager. Use when creating new screens, popups, or setting up navigation between them.
> defold-skill-maintain
Maintains Defold agent skills. Use when asked to update link lists in api-fetch/docs-fetch/examples-fetch skills, create or update proto file references, or fetch proto schemas.
> defold-shaders-editing
Creates and edits Defold shader files (.vp, .fp, .glsl). Use when asked to create, modify, or configure any Defold vertex shader, fragment shader, or GLSL include file.