Destroying AStarGrid2D

Godot Version

4.3

Question

I use player.gd script similar to this:

extends CharacterBody2D

var aStarGrid: AStarGrid2D

func _ready():
    aStarGrid = AStarGrid2D.new()

After that I use aStarGrid for something.

The CharacterBody2D is the player.gd script.

At certain point I queue_free() the CharacterBody2D so i can create new level and then create player again by instantiating.

My question is - is the aStarGrid also destroyed/freed at the point of queue_free() if it is part of the player.gd script like above? Or it must be explicitly freed?

Is there a debugger where I can see which variables are still instantiated similar to “Remote” tab?

I can see it is RefCounted so my assumption it would be free automatically, but I am not sure.

I’ve never heard of AStarGrid2D (it’s not in the list of controls or nodes), but if it’s parented to the player, and the player is properly destroyed, it should be cleared.

If you want to know, get to the state after the player has been destroyed while the game is playing and check the Remote section of the IDE and check if the player and its children are still there.

Example of my Remote section when it’s running.
{D0EB4B21-FA23-4787-91EB-D216CFE7D813}

It is not a Node, it is a Class.

It is not well known but it is very useful:

I am aware of the “Remote” section, the classes do not show up there, they are not inherited from “Node”.

It inherits “RefCounted” it will be destroyed when nothing has a reference to it. Player is destroyed, one less reference, if nothing else references this object then it will be destroyed with the player.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.