This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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)

2 Answers

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 (188 points)
0 votes

If you instanced a scene but haven't added it as a child anywhere in the active scene, you can call get_parent() on the instance to see if it has a parent. It can be used in an if statement to see if it's loaded in the scene.

by (50 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 Frequently asked questions and 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 [email protected] with your username.