@Meruva said:
Awesome! apologies I have been at work until late. Thank you very much for taking the time to find it. Thanks to everyone actually much appreciated the support and guidance on this!
No problem :smile:
You said you used a yield like it was a sub-opimal approach, can you elaborate on that a bit please?
Sure! The reason behind yield being sub-optimal in this case, and in several others, is that it can lead to timings being incorrect and hard to debug. Yielding, essentially, pauses execution of the function until the condition within the yield is satisfied, but other code (including in the node!) can still execute while the function is yielding (including another call to the same function).
This can lead to issues if you, for example, have a yield waiting and then delete the node, as once the yield resumes the node is no longer present. Another example is if you have a yield in _process
that is waiting on the results of a timer, and because _process
is called every frame, you might have multiple instances of the functioning yielding at once, which can cause issues when the yields finish waiting and execute.
All of that said though, there are times where using yields is fine and even advisable, it just needs to be used with caution. In this case, it's not really a big deal because it's yielding just for a single physics frame to apply velocity and only on the one object, where it's unlikely something could happen to the object in such a short time.
In theory you could use a Timer node or another similar solution to remove the yield, but I think it's probably fine in this case. It's just something to be aware of as it can cause issues in certain scenarios.
If anyone has anything I could read/watch that would have helped me find an issue like this I would be very open to that, maybe something that explained to me more about the nuances of the physics_process so I could have caught this problem myself, it seems like there is a gap in my knowledge here.....as well as many other places haha
I don't have anything, unfortunately, that I can point to. I only tried changing the modes to work around the physics server because I've had similar issues and had to learn the hard way after hours of debugging :lol: