Hey everyone!<br /><br />I am creating some inventory boxes which will allow the user to drag and drop items between them.<br /><br />The problem is since set_drag_preview only works when you set it when it's inside the
get_drag_data
function.<br /><br />Thus, you cannot do something like this:<br /><br />
<br />&nbsp; &nbsp; &nbsp; &nbsp; var TestButton = get_node(&#039;Button 2&#039;)<br /> var cpb = ColorPickerButton.new()<br /> <br /> cpb.set_size(Vector2(150, 150))<br /> TestButton.set_drag_preview(cpb)
<br /><br /><br />You have to actually add a gdscript inside the Button 2 node itself, and use this:<br /><br />
func get_drag_data(pos):<br /> # Use another colorpicker as drag preview<br /> var cpb = ColorPickerButton.new()<br /> <a rel="nofollow" target="
blank">#cpb</a>.set_color(&#039;red&#039;)<br /> cpb.set_size(Vector2(150, 150))<br /> set_drag_preview(cpb)<br /> # Return color as drag data
<br /><br />The problem is, I would need to create a seperate gdscript file for each inventory box I create. Which would be unintuitive I think.<br /><br />Infact, when doing set_drag_preview dynamically by using get_node, it actually starts the dragging process without even starting the drag.. It's weird, but here is the example:<br /><br />Create a simple button on your scene, then add this code inside ready():<br /><br />
<br />var TestButton = get_node(&#039;Button&#039;)<br />var cpb = ColorPickerButton.new()<br /> <br /> cpb.set_size(Vector2(150, 150))<br /> TestButton.set_drag_preview(cpb)
<br /><br />Now when the app starts, the drag preview starts automatically without even dragging, very weird. I'm obviously new to Godot so I'm probably screwing up somewhere, hope you guys can help thanks!<br /><br />