I think you should try the has_node()
not really sure if get_node_or_null()
will work
Yeah this wonât work in this case youâd need the reference not the path.
I was talking about has_node()
or get_node_or_null()
where youâd need the path as a parameter like
has_node(target1path)
Sorry for confusion
So not like this?
Depends what you are gonna use.
Are you gonna use has_node()
?
This line is not necessary
But isnât has_node() for checking child nodes? (sorry iâm a bit lost)
So i could check the parentâs node and see if is has the node
Ok let me give you a proper example
Var targetPath
func _ready():
targetPath = TargetNode.get_path()
func hurt():
if has_node(targetPath):
# rest of the code
Not necessarily
It worked thanks so much, i was trying to fix this bug in my game for 2 days! thank you, and sorry if i wasted your time by being dumb
Iâm sorry too, took me way to long to properly explain
I had this. Donât check for null as it wonât work with freed nodes: those exist in limbo for a moment. use is_instance_valid(node) instead
@TheOneAvailable Remember the SceneTree and how callbacks and notifications are sent is important to keep in mind.(see quoted blocks below)
- Godot notifcations
_notification()
are super important to understand and higher level are the overridable functions themselves
A few others that I have used in various ways for your use case (depending):
can_process()
- NOTIFICATION_DISABLED
- NOTIFICATION_READY
- tree_exiting()
- is_node_ready()
- request_ready() - probably an often overlooked one
- queue_free() <âREMEMBER! you can call this multiple times!
⌠and I could go on âŚ
Spend a day trying things out on these 2 MOST IMPORTANT pages, and youâll save years of headache:
- The entire single page on Class â Node
- All of the sections in â Best Practices
Scene tree: The SceneTree contains the active tree of nodes. When a node is added to the scene tree, it receives the NOTIFICATION_ENTER_TREE notification and its _enter_tree callback is triggered. Child nodes are always added after their parent node, i.e. the _enter_tree callback of a parent node will be triggered before its childâs.
Once all nodes have been added in the scene tree, they receive the NOTIFICATION_READY notification and their respective _ready callbacks are triggered. For groups of nodes, the _ready callback is called in reverse order, starting with the children and moving up to the parent nodes.
This means that when adding a node to the scene tree, the following order will be used for the callbacks: _enter_tree of the parent, _enter_tree of the children, _ready of the children and finally _ready of the parent (recursively for the entire scene tree).
This is a way better solution, thank you
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.