I have a scene as such:
where the main scene has a show_title
variable and before I export the game I run the following plugin:
tool
extends EditorExportPlugin
class_name CustomExportPlugin
func _export_begin(features, is_debug, path, flags):
# do some checks before exporting
...
How do I set the show_title=true
within the Main.tscn
every time before exporting?
Note: I am using godot version 3.5
tool
scriptYou load
the scene.
var my_scene := load("res://main.tscn") as PacketScene
You instance
it (instantiate
in Godot 4).
var my_instance := my_scene.instance()
You modify the instance:
my_instance.show_title = true
You package it again:
my_scene = PackedScene.new()
scene.pack(my_instance)
And save it:
ResourceSaver.save(my_scene, "res://main.tscn")
Yes, this modifies the project. And no, EditorExportPlugin
IN GODOT 3, does not make this any easier.
IN GODOT 4 you can override _begin_customize_scenes
to return true, and override _customize_scene
to return the modified PackedScene
. This way you don't have to save it, and thus the project is not modified.
In the script on the root of main.tscn
:
func _ready() -> void:
show_title = true
If you need this set before _ready
, you can do it in _init
instead.
If that script is not a tool script, that won't happen in the editor. If it is, then you can check if the code is running in the editor with Engine.editor_hint
(Engine.is_editor_hint()
in Godot 4).
🤷