Skip to content

Instantly share code, notes, and snippets.

View tracefree's full-sized avatar

Rie tracefree

View GitHub Profile
@tracefree
tracefree / gltf_animation_annotation.gd
Last active March 22, 2025 21:14
Example script for adding extra animation data based on GLTF custom attributes added in Blender when importing into Godot using GLTFDocumentExtension
# Example script for adding extra animation data based on GLTF custom attributes
# added in Blender when importing into Godot using GLTFDocumentExtension.
# (This example depends on other scripts not included here so it doesn't run on its own.)
extends GLTFDocumentExtension
const FPS = 60.0
func _import_preflight(state: GLTFState, extensions: PackedStringArray) -> Error:
if not state.json.has(&"animations"):
@tracefree
tracefree / 01_mod_loader.gd
Last active February 4, 2025 13:58
Mod loading system for Godot, allowing changes to the same scene or resource file to be merged gracefully when possible
extends Node
## Mod Loader
##
## Add this as the very first autoload in your project settings.
const MODS_PATH = &"user://mods"
const MODLIST_PATH = "user://modlist.cfg"
const MODS_SECTION = &"Load mods"
var da: DirAccess
@tracefree
tracefree / nested_enums.gd
Last active September 13, 2024 10:40
Quickly hacked together example for how one could expose a different "sub" enum variable depending on the value of a "main" enum.
@tool # <- This is important, only works in tool scripts
extends Node
## Nested enum example
##
## Quickly hacked together example for how one could expose a different "sub" enum variable
## depending on the value of a "main" enum.
# Main enum
enum MainClass {
@tracefree
tracefree / properly_transforming_navigation_obstacle_3d.gd
Last active September 8, 2024 17:28
Godot tool script that updates the vertices of a NavigationObstacle3D when rotating the node. First add the vertices as you normally would, then check the "store vertices" checkbox in the inspector. After this the rotation is applied to the vertices making up the obstacle. For older Godot versions change `@export_storage` to just `@export`.
@tool
extends NavigationObstacle3D
@export var store_vertices := false:
set(do_store):
if do_store: original_vertices = vertices
@export_storage var original_vertices: PackedVector3Array
func _ready() -> void: