nodes id is changing in the exported file

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By nah

godot v3.3.2 stable
the node is a kinematikbody2d
exported to Linux

in debug run, i have 1212 as the node id, but when i export the scene, the node becomes 1173. and so my “if” statements are not working.

all the children nodes are different in the same way. 1212,1213,1214 in debug run. and 1173,1174,1175 in exported file run.

on_body_shape_entered(body_id, body, body_shape, local_shape):
      if body_id == 1212:
           do_something()

Thank you

:bust_in_silhouette: Reply From: Calinou

Node IDs are not stable across project runs. Instead, you need to rely on something else such as an inheritance check (if node is KinematicBody2D), a method-presence check (if node.has_method("roll_over")) or a node name check (if node.name == "SomeNode").

The is approach is recommended most of the time, as it is the strongest in terms of safety. Node names should only be used as a last resort, as they will not work if the node is duplicated at the same level. This is because Godot does not allow several nodes to have the same name at the same level in the scene tree.