Godot Version:
4.7.1
Problem:
I have a drag and drop system. The thing is that I have an auto-scroll feature that makes the scroll move with a certain speed. I noticed that if I have some high speed, my data is dropped into another node, not the one that was dropped, and it is in the opposite direction of the movement (nodes that I leave behind when I move).
I am guessing that the node is dropped before the scroll is calculated (although when I debug, it looks fine) and it targets another node.
I have thought that the only solution would be to wait and draw the frame before _drop_data() is called, but even then I do not know if the values it receives would be correct.
I have already thought about âguessingâ the data. I could stop _drop_data() and manually call it with the drag data once I have drawn, but I do not like this solution and maybe it would not be possible.
Waiting (await get_tree().process_frame) when the scroll is drawn does not solve this.
The application is Taskesy 2 on Steam and it happens when I move boxes or columns through the scroll at a high speed.
A _drop_data just gets a position relative to the control, so Iâm not really sure what waiting a frame would achieve.
What is your control hierarchy and where on it are you testing for the drop data?
My guess is youâve got it on something to do with the scroll itself rather that what is being scrolled? Iâd suggest you might need to place _drop_dataâs etc onto the components youâre wanting to get the data rather than trying to calculate which component the drop should refer to? As I havenât seen what youâve done, itâs just a (very) wild guess which may be completely off the mark.
To simplify things, basically my boxes can be dropped to other boxes. The thing is that I have made an auto-scroll system so when you move a box in the direction where you want to move to another box, if the scroll is big you will be moving at a high speed.
If I drag and drop while I have a lot of speed, the box where I dropped the dragging box does not receive the dropping box; it is another one.
Letâs see an example. Imagine that there are from 0 (top of the scroll) to N (bottom of the scroll) boxes in a vertical scroll, and I am dragging the box at index N-2. There are a lot of boxes between 0 and N, so I want to move the box upwards in the scroll. When I get a lot of speed when moving to the top due to the auto-scroll system. If I were to drop the dragging box (N-2) to box 0, although I drop it at box 0, another box will receive the dropping box (N-2), for example, box 6.
That is my problem, it should have been dropped to box 0, but box 6 receives the dragging box and its _drop_data() function is called, not the one of box 0.
My approach to waiting frames was to see if at the moment when I drop the dragging box, the scroll may not have been calculated properly so the position is the one of another box.
The boxes have a script with the _drop_data() function, I do not guess anything, that was just a possible (unwanted) solution.
Here you have a real example of my problem. In the first part, you see that I drag and drop the box to box â0â, but the box appears elsewhere. This only happens at a high speed and then I showcase the normal behaviour in two different boxes.
Maybe this example showcases that waiting frames might not be a solution either, because the scroll looks good at the moment of dropping the box and the receiving node is very far from the intended box 0.
If the speed is not this fast, then the auto-scroll system always works fine.
Well I said it was a wild guess as to what your code might be doing and that I could be completely off the markâŚ
Anyway, looking at your video, it would appear that your auto scroll routine is doing something with testing that youâre on the first item of the scroll area? You probably need to be looking at that code rather than on the drop side of things. The thing is that youâre not really in control of what the server will say is the box you dropped it on, so Iâm drawing a blank on what you can do to fix it.
However mulling it over you may be able to get around the issueâŚ
I notice you canât drop between the boxes. It might make sense if you could anyway so perhaps you need to implement it in one of the ways I was guessing you might have been trying to implement it.
You could just do this when the screen is scrolling rather than all the time. To do that just say that you canât drop on a box if your auto-scrolling is scrolling. That should pass the drop mechanism onto the next drop mechanism.
Then add drop code to the container inside the scroller. This should then run when over the gaps between the boxes and when the boxes arenât accepting drops (e.g. when auto-scrolling). If your boxes are all the same size as in the video then you should be able to calculate the box via the position / (box size + gap size). I suspect the boxes arenât going to all be the same size outside your demo scenario. Not sure how you could calculate which box it was then. It may turn out the position is still incorrect anyway and would give you the wrong coordinate, so it might be worth experimenting by implementing this just to see if you get a value near 0 for the y position or say 1000 or more which would be about where row 13 would be. Knowing both get it wrong might tell you something (although not sure what).
If the issue is just when you drop at the top you could also use the above mechanism and then only use the drop if the y position is less than the size of the first box, therefore presuming any larger number is one of the gaps and therefore not supported? In that respect it could be a work around.
Thank you very much for your reply!
First of all, it only happens when the speed of the auto-scroll is high, so there is no special code for an item being first or something similar. You can recreate this behaviour in every box if you have enough (high) speed.
Secondly, the drag and drop system should be correct as it works as expected in any normal situation.
The problem comes just when scrolling with at a high speed. I do not know if it may be a Godotâs bug at this point, because it is clear that I drop the dragging box into another one and it is not its own signal the one it is emitted; another node receives the dragging box. Even if it is something that I did incorrectly on my own, isnât it strange that I clearly drop a box into another one and do not receive the data only when the speed of the scroll is high (and another passed box receives it)?
Even if you donât intend to use what I mentioned before in your final code, I think you should try it out to see what coordinates the system reports the drop at when high speed scrolling.
Another thing to try would be to see which boxes are getting âlooked atâ by the drag system, e.g. put a print statement in the boxâs _can_drop_data function to see which ones are being called and in what order (although Iâm not 100% sure the order of printing is guaranteed - I know itâs not in some languages - so you might need to put an array in a singleton and append to it etc). As itâs speed based you canât realistically step through what is happening with the debugger. See if this correlates with the drop answer youâre getting.
Actually that probably answers your original question âIs there a way to execute commands before â_drop_data()â?â : Yes, _can_drop_data() runs before _drop_data(). Iâm not sure it will help. The problem there will be that even if the _can_drop_data gets called correctly before the _drop_data gets called incorrectly (in which case you could think that you could store the correct drop place and patch the drop etc), I believe that on a _drop_data the _can_drop_datais called directly before it so the last _can_drop_data call should be on the same box as the actual _drop_data call.
If you also do the adding of _can_drop_data on the container within the scroller then you should also see when this is occurring between the boxes, it might turn out to be something along the lines of the drop attempting to happen on one of the gaps and the last box that was identified is used for the drop instead (wild speculation), but thatâs just one conjured up theory so youâll need to try a few things to find more data points to come up with a viable prognosis.
PS I only came on the forum to write up and publish some code on an issue I had that I couldnât find any information on anywhere and eventually worked out how to do it, in case anyone else wanted to do the same thing. Namely picking objects in the 3D scene editor which were in sub-scenes of the one being edited and had been moved by code in other tool scripts, as it turns out the collision positions are stale in the editor so you canât use standard ray-casting as it gives you phantom results. I may eventually get around to writing it. Your issue of phantom results seemed somehow relatable to me.
Thank you for your answer once again!
I tried waiting in _can_drop_data() before I published my question, but it did not solve my issue so I discarded the approach, but yeah, debugging the text of the box was super important and I missed it.
When the scroll reaches a certain speed, the boxes are not processed by _can_drop_data(), so your guess was correct; the box ends up in the last seen node by _can_drop_data().
I will try to solve this or I will take a âguessâ approach with coordinates. Worst-case scenario is that I cancel the drop if the speed is really high.
And yeah, I have been doing this app for around 10 months (not full-time though) and I get very strange bugs, maybe because it is less normal to do this kind of app with Godot and there is less information about them. This forum is so helpful because there are kind people like you who are really life-savers.
With _mouse_entered() the behaviour is exactly the same as what I have seen with _can_drop_data().