Hello, my problem is relatively simple: I have a mechanic in my game wherein the player is able to grapple enemies and be dragged around by them. I do this by having the enemy turn into a child of the player, and when the enemy is released from the grapple it is immediately reparented to the node it was under before.
The function works, mostly. However, when I release the enemy too quickly, the game crashes and an error DOESN’T post to the terminal(?). Is there a known error with this, because a lack of an error post is making a fix very hard to find.
Everything that can be interacted with and or that moves is under the “Entities” node, this is for organization. As such, it is the shared parent of the PLAYER and the GHOST entity. When the GHOST enters the PLAYER’s camera (an Area3D that appears for a second) it is reparented with the PLAYER as its new parent using this command:
func _on_camera_body_entered(body: Node3D) -> void:
if body.is_in_group("GHOST") and GHOST_STUNNED == true and GHOST_SNAGGED == false:
IS_CAPTURING = true
GHOST_SNAGGED = true
body.reparent(self)
GHOST = body
Then when this command is run, the GHOST is reparented to the aforementioned “Entities” node:
if Input.is_action_just_released("MOUSE1") and IS_CAPTURING == true and GHOST_SNAGGED == true:
await get_tree().create_timer(.2).timeout
GHOST_SNAGGED = false
IS_CAPTURING = false
if GHOST.HEALTH >= 0:
GHOST.reparent(WORLD_PARENT)
The “WORLD_PARENT” is just the “Entities” node. These two commands work fantastically, UNLESS they are run very quickly next to eachother. Something about the speed makes them bug out and pseudo-crash the game.
This await is probably the problem. I’m not 100% sure but maybe the state changed after those 200ms and GHOST may be pointing to a null value or an already freed Node.
I’m not sure what the fix would be as I’m not fully understanding the issue but try checking again the IS_CAPTURING and GHOST_SNAGGED variables after the await and also check if @GlobalScope.is_instance_valid() the GHOST variable.
So strangely enough, the AWAIT function was not the issue, but the it was actually the IS_CAPTURING and GHOST_SNAGGED booleans. I swapped them to run AFTER the GHOST is released, and the issue VANISHED. I’m still not really sure what in the world the error was, as I still never got and error posted, but it works now!