From e857e597464b90e3c316af3fdf0f6c0567426b30 Mon Sep 17 00:00:00 2001 From: Douglas Carmichael Date: Wed, 5 Aug 2026 15:44:55 -0400 Subject: [PATCH] Add $uuid() template function for hyphenated UUIDs $uid(N) emits a v4-random id as 32 hex digits without hyphens, which is what Unity .meta guids need, but some export formats require the canonical hyphenated UUID form (e.g. the manifest of Imaginando VS 2 shaders, see #1533). $uuid(N) returns the same cached id as $uid(N) for the same index, in 8-4-4-4-12 hyphenated form (the version/variant bits set by get_uid() already make it a valid UUIDv4). Existing $uid() users are unaffected, and the two patterns cannot be confused by the regexes since "$uid(" is not a substring of "$uuid(". --- addons/material_maker/engine/nodes/gen_material.gd | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/material_maker/engine/nodes/gen_material.gd b/addons/material_maker/engine/nodes/gen_material.gd index 21557308d..43b7dc0fc 100644 --- a/addons/material_maker/engine/nodes/gen_material.gd +++ b/addons/material_maker/engine/nodes/gen_material.gd @@ -597,7 +597,20 @@ func get_uid(index : int) -> String: uids[index] = uid return uids[index] +func get_uuid(index : int) -> String: + # Same id as get_uid(), in canonical hyphenated (8-4-4-4-12) UUIDv4 form + var uid : String = get_uid(index) + return uid.substr(0, 8)+"-"+uid.substr(8, 4)+"-"+uid.substr(12, 4)+"-"+uid.substr(16, 4)+"-"+uid.substr(20, 12) + func process_uids(template : String) -> String: + var uuid_regexp : RegEx = RegEx.new() + uuid_regexp.compile("\\$uuid\\((\\w+)\\)") + while true: + var result = uuid_regexp.search(template) + if ! result: + break + var uuid = get_uuid(int(result.strings[1])) + template = template.replace(result.strings[0], uuid) var uid_regexp : RegEx = RegEx.new() uid_regexp.compile("\\$uid\\((\\w+)\\)") while true: