Need a fast way to delete A Node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Abdulrahman

Hi ,

I’m facing problem when i’m using queue_free() or even free(), the time it takes to delete a Node is long, which in my case causes problems. is there a faster way to delete nodes ?

Srsly? How long does it take to get deleted for you?

SIsilicon | 2018-12-11 19:09

I don’t think there is a faster way, or even another way. How did you measured how long it takes to be deleted?
Perhaps if you tell us more info we can think a trick so that the node does not cause problems to you while waiting to being deleted.

p7f | 2018-12-11 19:19

I did not calculate how much time yet I’m getting a response by another object that it’s still not deleted

Abdulrahman | 2018-12-12 06:25

I did not calculate how much time yet I’m getting a response by another object that it’s still not deleted.
Let assume the following : Object x has multiple node inside of it. Let assume three objects y, z, and p are connected to x
Y: is spikes that kills the player
Z: is the object you try to hit
So let me explain what am I doing so you get better understanding.
I have a ball, when this ball hits Z. It should delete Z and Y and not X because p will be created by the code.
Y kill the player.
The problem is when I hit Z by the ball I also got hit by Y before its been deleted.
I used delta for the ball speed

Abdulrahman | 2018-12-12 06:37

:bust_in_silhouette: Reply From: shield

Maybe your answer may not be to queue_free() or free(), but to check whether the ball has hit Z when Y hits the player, if it does, not to kill the player, to hide the node, and to disable collisions with player through add_collision_exception_with( Node body ).

Also, how do you use delta for the ball_speed? Assuming you use kinematicbody2d, move_and_slide() already helps calculate for delta, so there’s no need for delta.

Thanks, I did not know that move_and_slide() uses delta.
I tried to use queue free and free, sometimes it does work and sometimes there was a little delayed behavior. It feels like the Y is not deleted quick enough while I’m using signals. I tried to hide it, change the layer. But the signal was slow

Abdulrahman | 2018-12-12 07:20

I think that what @shield says in his answer should work. If you can share the code or the project may be we can help solve the problem better.

p7f | 2018-12-12 13:26

I decided to change how the collision works and i fixed it.

Abdulrahman | 2018-12-12 17:44

What did you do?

shield | 2018-12-12 17:45

i had to change the collision , my problem was because of the collision, i tried to detect collision through is_on_wall() how ever this method cant be used if the object is moving and causes to my game some lag. that was problem number 1. problem 2 was is depending on the situation sometime it detect the collision and sometime it does not. when i changed the collision, the signal delivered faster and i don’t know why but that was the result

Abdulrahman | 2018-12-19 16:12