Hello,
I'm facing an issue with resources and the Local to Scene setting.
I have a scene with a Path2D holding a Curve2D ressource. I use it to form curved 2D areas in the editor for my game, which are then converted to Polgyon2Ds and Area2Ds on startup by baking the curve points and using those point arrays.
Naturally, I want to create different shapes with most of the instances of this scene in my main scene (from the editor, that is), so I tried to fiddle around with making the Curve2D unique as well as setting Local to Scene. This works more or less:
If I repeatedly drag the scene instance into my main scene, the curve is always unique and everything is fine. But this is a bit tedious, having to drag it over and over.
But I have to do it this way instead of duplicating, since when I duplicate, the curve is no longer unique! I would have to go and click into the resource of the node and save it again as unique, which is an even bigger workflow break.
Mainly I want to ask: Is there some other way, am I missing something? Or is that the expected behaviour and I will have to deal with it?
Curves Local to Scene are copied on Duplicate?
Thanks for your suggestion. I went ahead and made an editor plugin for that (tools themselves can not access EditorSelection as I had to learn).
Here's my code for any other who stumble across this issue:
extends EditorPlugin
var select: EditorSelection
var action_name: String ="DuplicateUnique"
var group_name: String = "unique_duplication"
func _enter_tree() -> void:
select = get_editor_interface().get_selection()
# now add the action and the event if not there yet
if not InputMap.has_action(action_name):
InputMap.add_action(action_name)
# make event for D + Shift + Ctrl (to not coincede with normal duplicate shortcut)
var event: InputEventKey = InputEventKey.new()
event.key_label = KEY_D
event.shift_pressed = true
event.ctrl_pressed = true
InputMap.action_add_event(action_name, event)
func _exit_tree() -> void:
if InputMap.has_action(action_name):
InputMap.erase_action(action_name)
func _process(_delta: float) -> void:
if Input.is_action_just_pressed(action_name):
var selectNodes: Array[Node] = select.get_selected_nodes()
if len(selectNodes) == 1:
var node: Node = selectNodes[0]
# hereafter follows node specific duplication procedure
if node.is_in_group(group_name):
var newNode = node.duplicate()
newNode.curve = newNode.curve.duplicate()
node.get_parent().add_child(newNode)
newNode.owner = node.owner
# take old nodes name, engine will automatically increment a number to avoid name collision
# otherwise, you get ugly names
newNode.name = node.name
The implementation of the duplication is naturally unique to my case (which ressource exactly shall be duplicated), but that can be easily adapted. I chose Shift + Ctrl + D as shortcut. I also limited the tool to only duplicate when a single node is selected. Nodes need to be in a special group to allow unique duplication (to avoid running into errors when using the shortcut while another type of node is selected.