Godot Version
4.3
Context
I have a change_state()
function in Player
class (with current_state
member)
When i call the function with parameter like this (ActiveState
inherit State
inherit Node
):
Or like this:
Question
Should i free()
or queue_free()
the current_state
before assigning new_state
in change_state()
function?
This depends on what State extends from. Usually you store all states in an array and then activate the current one instead of deleting and creating new ones
Oh, State
extends from Node
. I just trying to find the best way to use state machine for my game, and then i wonder if i should free()
that object or godot do it for me.
Thanks for advices about array anyway.
Nodes dont free themselves. If you want to delete them you have to call queue_free on them (or their parent if they are inside the scenetree)
1 Like