All Questions

Community

Daniel Queiroz Porto
posted to: The Spawn State

Won't "if owner.camera_rig" crash the game if there's no camera rig?

I left the code there because I was using the camera, and it crashed because I didn't have any variable in owner named "camera_rig". Shouldn't it be:

if "camera_rig" in owner:
  #Do your stuff

Like the second answer here: https://godotengine.org/qa/3099/check-if-script-of-a-node-has-variable (not the one marked as correct)

  • Nathan Lovato replied

    It does not crash, just tells you there's an error - it's pretty safe in Godot. But yes, if I wrote that code, it's way better to... not even use the if statement, either code with the camera or without.

  • Daniel Queiroz Porto replied

    Yeah, I ended up doing that, and moved the camera call to inside the player's set_active method, since I already know the camera is there.

    Oh and I didn't know that happened only when running in the editor, good to know as well! Thanks for the reply!