0 votes
extends Control

onready var Debug = $Debug

onready var player = get_parent().get_node("PlayerCharacter")

onready var player_state = player.STATE

onready var player_physics = player.PHYSICS


func _process(delta):

    Debug.text = "FPS: " + str( Engine.get_frames_per_second() ) + "\n"

    for n in player_state:

        Debug.text += str( n ) + ": " + str( player_state[n] ) + "\n"

    Debug.text += "\nVelocity: " + str( player_physics.VELOCITY )

This only works if this GUI control is loaded after the playercharacter node from my understanding. Is there a way to have a conditional statement that I can implement in process() to check if the player node in the tree is loaded before calling process code?

in Engine by (12 points)

1 Answer

0 votes

Before answering, one quick tip, you can replace

onready var player = get_parent().get_node("PlayerCharacter")

with

onready var player = get_node("../PlayerCharacter")

To know wether the node is loaded, you can use the has_node(name : String) method on its potential parent node. It returns a bool value (true if it has the node with the name you gave as an argument).

by (176 points)
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.