Hello,
I have multiple SubViewports, each with a duplicate of the same scene. This works okay, but if I want to move a node, I have to move it separately for each copy of the scene. Is there a better way to do this so that if I move a node in one copy, it moves in all the copies?
Here is what the structure of the game looks like:
Here is the code I am using to move the node across all three copies:
extends Node
@onready var remotes = Controllers.remotes
@onready var players = [
get_parent().get_node("HBoxContainer/SubViewportContainer/SubViewport/Testscene/Sprite2D"),
get_parent().get_node("HBoxContainer/SubViewportContainer2/SubViewport/Testscene/Sprite2D"),
get_parent().get_node("HBoxContainer/SubViewportContainer3/SubViewport/Testscene/Sprite2D")
]
func _process(delta):
for player in players:
player.global_position = Vector2(player.global_position.x+10*delta,player.global_position.y+10*delta)
Unique names could help you out, seems alright to me though. Since Testscene is already an instanced scene I’m not sure what friction you are encountering for each “copy”.
If you do end up using Unique names, make sure to call them from a parent script, the root node game would work best.
That certainly simplifies things a lot. Not quite what I had in mind, but it should certainly shorten the code. I guess I’ll just continue to loop through each scene copy then. Thanks