0 votes

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

in Engine by (27 points)

1 Answer

+3 votes
Best answer

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.

by (10,972 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.