Skip to content

Instantly share code, notes, and snippets.

extends Node
func pack(p:Node)->PackedScene: var v = PackedScene.new(); v.pack(p); return v
class A extends Node:
@export var m: String = "a"
static func instantiate(p:PackedScene):
var v: A = p.instantiate()
v._post_init()
return v
@Gnumaru
Gnumaru / FinalOrReadOnlyPropertiesExample.gd
Created October 29, 2025 13:27
how to simulate in gdscript a class property that can be asigned only the first time, like a 'final' property in java or a 'readonly' property in C#
# how to simulate a class property that can be asigned only the first time, like a 'final' property in java or a 'readonly' property in C#
#class_name ReadOnly
extends Node
# READONLY NON OBJECT WITH SPECIFIC TYPE
var readonly_int:int:
set(p):
if readonly_int != 0:printerr('cannot set readonly property "readonly_int" a second time'); return
readonly_int = p