Godot Version
4.5
Question
Hello everyone!
For my game for levels building I use @tool gdscript, which simplifiesthe creation of the levels. This tool script is connected to a bunch of nodes on each level.
The goal is to keep scripts at their nodes in editor, and export levels (scenes) and it’s nodes without scripts. So I need export script, which takes level on export, modifies it and exports without saving project files, but I stucked with it.
For now I wrote a plugin, which extends EditorExportPlugin:
@tool
extends EditorExportPlugin
var c : int = 0
func _export_begin(features: PackedStringArray, is_debug: bool, path: String, flags: int) -> void:
pass
func _begin_customize_scenes(EEP : EditorExportPlatform, S : PackedStringArray) -> bool:
return true
func _get_name() -> String:
return "ExportCleanUpPlugin"
func _export_file(path: String, type: String, features: PackedStringArray) -> void:
if type == "PackedScene" and path.contains("res://Scenes/Levels/"):
var scene: PackedScene = load(path)
if scene:
var root: Node = scene.instantiate()
if root:
_strip_scripts(root)
var modified_scene = PackedScene.new()
modified_scene.pack(root)
ResourceSaver.save(modified_scene, path)
root.queue_free()
print("Export: %s -> Deleted scripts: %d" % [path, c])
c = 0
func _strip_scripts(node: Node) -> void:
if node:
var script = node.get_script()
if script and script.is_tool() and "BlockGenerator.gd" in script.resource_path:
node.set("script", null)
c += 1
for child in node.get_children():
_strip_scripts(child)
But it rewrites my project files (levels), and seems like doesn’t work (as I see error messages in console about this script).
I also tested _customize_scene (with _begin_customize_scenes returning true and implemented _get_customization_configuration_hash) but this method is called only if scene was changed since last export, and also doesn’t delete scripts for me. Am I missing something?