Scroll Container and Reparenting

Godot Version

4.1.3

Question

Hello folks.
So I have am having an issue with Scroll Containers, and a Drag & Drop system I built based on this video: https://www.youtube.com/watch?v=uhgswVkYp0o&pp=ygUTZ29kb3QgZHJhZyBhbmQgZHJvcA%3D%3D

I have a very similar setup to what the video has with the following code on the object:

extends Node2D

#variables for Drag & Drop
var draggable = false
var isInsideDroppable = false
var bodyRef
var offset: Vector2
var initialPos: Vector2 #stores initial position of object

func _process(delta):
	#code for Drag & Drop
	if draggable:
		if Input.is_action_just_pressed("Left Click"):
			initialPos = global_position
			offset = get_global_mouse_position() - global_position
			Global.isDragging = true
		if Input.is_action_pressed("Left Click"):
			global_position = get_global_mouse_position() - offset
		elif Input.is_action_just_released("Left Click"):
			Global.isDragging = false 
			var tween = get_tree().create_tween()
			if isInsideDroppable:
				tween.tween_property(self, "position", bodyRef.global_position, 0.2).set_ease(Tween.EASE_OUT)
			else:
				tween.tween_property(self, "global_position", initialPos, 0.2).set_ease(Tween.EASE_OUT)

#Select Area connect Signals
func _on_select_area_mouse_entered():
	if not Global.isDragging:
		draggable = true
		scale = Vector2(1.05, 1.05)

func _on_select_area_mouse_exited():
	if not Global.isDragging:
		draggable = false
		scale = Vector2(1, 1)

func _on_select_area_body_entered(body:StaticBody2D):
	if body.is_in_group("dropable"):
		isInsideDroppable = true
		bodyRef = body

func _on_select_area_body_exited(body):
	if body.is_in_group("dropable"):
		isInsideDroppable = false

Then I have a “Platform” for the object to slot into that is as follows:
Control
->Area2d

The platform control node is inside a SrollContainer and I have no problems when trying to scroll with just the platform inside the ScrollContainer.
However, when I drag and drop the object into the platform, it does not scroll with the ScrollContainer when scrolling.
I have tried to reparent the object to the platform’s control node, but when I do that the object’s position gets messed up and it no longer is in the correct spot.
Would anyone have any insight as to why the position gets messed up when reparenting?

You could try to reset the position when you reparent() the node by setting keep_global_transform to false.

I will give this a try!