Check for existence of %Object?

Godot Version

4.3rc3

Question

i have a base class with %DeathAnimation. Because Godot can only inherit scripts, not scenes, the children don’t automatically have %DeathAnimation and that’s fine, some of the kids don’t need it.

Problem: How do i see if the thing exists?

This causes toooooons of errors:

# Node not found: %DeathAnimation
if null != %DeathAnimation:
	death_animation = %DeathAnimation

# Also Node not found: %DeathAnimation
if is_instance_valid(%DeathAnimation):
	death_animation = %DeathAnimation

try find the node instead, also that’s % unique name node, it only applies for that scene who has it, other scene wont have that unique name node accessible like that

1 Like

Cool, that works! And solves a minor issue that’s been bugging me for weeks.

Option 1:

death_animation = get_node_or_null("DeathAnimation")

Option 2:

if find_child("DeathAnimation"):
1 Like

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