Godot Version
4.3
Question
I have troubles setting up a EditorPlugin script for map-making purposes. I am trying to do the following:
- Spawn a number of PackedScene instances on the selected GameObject
- Then, for each instance, manipulate the points of a Curve3D which is part of a Path3D node in the instance scene tree.
When I use my script, the instances are added correctly in the editor view and show up in the 3D preview, including the changed points of the Curve3D.
When I press play, the points are reset to the “default” values, saved in the PackedScene. I already activated “Local to scene” for the Curve3D resource, and tried different ways to add the instances to the SceneTree, including ownership settings.
Here is the SceneTree of the instances I am adding to the selected GameObject as a child:
the Path3D Node:
And my code in the EditorPlugin:
var selectedBundle = EditorInterface.get_selection().get_selected_nodes()[0]
var num_branches = float(branches_number_dock.get_node("LineEdit").text) if branches_number_dock.get_node("LineEdit").text != "" else 5
print("Frequency of branches:", num_branches)
var total_track_length = int(track_length_dock.get_node("LineEdit").text) if track_length_dock.get_node("LineEdit").text != "" else 800
# calculate needed length of each track
var track_length = total_track_length/num_branches
# -z is forward
for i in range(num_branches):
var track = baseTrackPreload.instantiate()
selectedBundle.add_child(track)
track.position = Vector3(0, 0, -track_length*i)
# set point positions
var path: Path3D = track.get_node("TrackPath")
path.curve.clear_points()
path.curve.add_point(Vector3.ZERO)
path.curve.add_point(Vector3(50, 0, -track_length))
track.get_child(0)._update_multimesh()
track.set_owner(get_editor_interface().get_edited_scene_root())
Is there something that I am doing wrong? Is there any way to make the Curve3D changes made from script persist after saving the modified scene?
Thanks for any help in advance!