Index of every page on this site: llms.txt
All skills
jame581 avatar

/gdscript-advanced

@426e8ab
by Jan Mesarčjame581/godotprompter979 stars
63
Run it yourself

Use when writing production-grade GDScript — performance idioms, metaprogramming, @tool lifecycle, async pitfalls, and signal/Callable trade-offs

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/gdscript-advanced

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencestool-script-recipes.md

≈714 tokens on demand. Your agent reads this file only when SKILL.md points to it.

@tool Script Recipes

Reference for skills/gdscript-advanced/SKILL.md — production-grade @tool script patterns.

← Back to SKILL.md


1. Editor preview for a procedural node

A @tool script that previews a procedural mesh in the editor without running the game.

@tool
class_name CircleVisualizer extends MeshInstance3D

@export var radius: float = 1.0:
    set(value):
        radius = value
        if Engine.is_editor_hint():
            _rebuild_mesh()

@export var segments: int = 32:
    set(value):
        segments = max(3, value)
        if Engine.is_editor_hint():
            _rebuild_mesh()

func _ready() -> void:
    if Engine.is_editor_hint():
        _rebuild_mesh()

func _rebuild_mesh() -> void:
    var arrays: Array = []
    arrays.resize(Mesh.ARRAY_MAX)
    var verts: PackedVector3Array = PackedVector3Array()
    # Godot 4 has no line-loop primitive: emit segments + 1 vertices so the strip closes.
    for i in segments + 1:
        var angle := i * TAU / segments
        verts.append(Vector3(cos(angle) * radius, 0, sin(angle) * radius))
    arrays[Mesh.ARRAY_VERTEX] = verts
    var array_mesh := ArrayMesh.new()
    array_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_LINE_STRIP, arrays)
    mesh = array_mesh

2. Baking a value at editor save time

@tool
extends Node

@export var bake_button: bool = false:
    set(value):
        if value and Engine.is_editor_hint():
            _bake_now()

func _notification(what: int) -> void:
    if what == NOTIFICATION_EDITOR_PRE_SAVE:
        _bake_now()

func _bake_now() -> void:
    # ... compute and write a baked Resource
    pass

3. Editor-only debug visualization

@tool
extends Node3D

func _process(_delta: float) -> void:
    if not Engine.is_editor_hint():
        return
    # Draw debug primitives that only show in the editor
    DebugDraw.draw_sphere(global_position, 1.0, Color.RED)  # addon (e.g. Debug Draw 3D) — Godot has no built-in debug-draw API

4. Common @tool bugs

  • Editor freeze on script reload — usually an expensive rebuild in a setter: it runs for every property as the scene loads and on every Inspector drag. Assigning the property inside its own setter does not recurse, but two setters that set each other do. Guard with an if value == current: return check.
  • Errors on add to scene — touching get_tree() or get_viewport() before the node is in the tree (exported setters run first); they return null with an error. Use if is_inside_tree(): guards.
  • Settings lost on reload — using @onready for tool state. @onready values are set only when _ready() runs, and after a tool script is reloaded in the editor _ready() may not run again — fetch nodes on demand, or use _ready with is_editor_hint() checks.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts7d3 checks · Risk SAFE
  • Gen Agent Trust Hub7d

    The skill is a set of technical guidelines for advanced Godot Engine development. It contains no malicious code, external dependencies, or security risks. In fact, it explicitly teaches security best practices, such as allowlisting method names when using dynamic dispatch to prevent potential exploits in game modding or networking.

  • Socket7d

    No alerts

  • Snyk7d

    Risk: LOW · No issues

Signed by skilld at 426e8ab. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated last week

README badge

README badge for jame581/godotprompter/gdscript-advanced