Hello,
I have a simple object that extends CharacterBody2D, and I'm trying to inspect the value of velocity.y in the debugger, where velocity is a member of CharacterBody2D. Is there an easy way to examine the value of velocity without printing it? I want to see it in the debugger.
Here is screen of the debug session , where can i see the velocity varibale ?

extends CharacterBody2D

class_name Bird
@export var gravity = 900.0
@export var jump_force = -300
var rotation_speed = 2

@onready var animation_player = $AnimationPlayer
var max_speed 	= 400

func _ready():
	velocity = Vector2.ZERO
	print("this is ready")
	
func _physics_process(delta):
	if Input.is_action_just_pressed("jump"):
		jump()
		print("this is jump")
	
	velocity.y += gravity+delta
	#print(velocity.y)
	velocity.y = min(velocity.y,max_speed)
	move_and_collide(velocity*delta)
	rotate_bird()
	
func jump():
	velocity.y = jump_force
	print(velocity.y)
	rotation = deg_to_rad(-30)

func rotate_bird():
	if velocity.y > 0 && rad_to_deg(rotation) < 90:
		rotation += rotation_speed * deg_to_rad(1)
	elif velocity.y < 0 && rad_to_deg(rotation) > -30:
		rotation -= rotation_speed * deg_to_rad(1)

When you run the game there should be a "remote" tab in the scene tree view. Click that, selected the respective node and find the property in the inspector.

  • umen replied to this.

    I don't see the velocity property for a CharacterBody2D in the Inspector.

    • umen replied to this.

      The velocity property is set to not be visible in the editor by default. You can change its editor status by overriding _get_property_list() for the node. The function needs to return an array of dictionaries with status of properties whose treatment you want to make different from default.

      func _get_property_list():
      	var properties = []
      	
      	properties.append({
      		"name": "velocity",
      		"type": TYPE_VECTOR2,
      		"usage": PROPERTY_USAGE_EDITOR
      	})
      
      	return properties

      Now the velocity will be visible in remote inspector.

      • umen replied to this.

        xyz
        Maybe is will work , but this is not good programming practice ,
        I just want to see it in the IDE

          Zini
          Yeah i I did read the documention , but it dosn't show any thing

          umen Maybe is will work , but this is not good programming practice ,
          I just want to see it in the IDE

          xyz's method solves the problem. Why is it not good programming practice?

          • umen replied to this.

            That's strange. I get all the properties displayed when I look at any of my objects, in stack variables and inspector.

            • umen replied to this.

              DaveTheCoder
              There is no language in the world that you need to do this stuff to view base class members if they public or protected or friend .
              And this is just the tip of why its bad

              • xyz replied to this.

                umen

                The same as you. You can see it in the lower-right corner.

                Now that I've created a new project with a CharacterBody2D though, I can't see the velocity either (unless I assign it to a variable). 🙁

                you can also make a var and export it, in your case as Vector2 *Edit: you don't need to export, just like duane said, you can achieve with a var

                umen There is no language in the world that you need to do this stuff to view base class members if they public or protected or friend .
                And this is just the tip of why its bad

                This has nothing to do with language. It is the editor issue, namely it's a matter of property display in the editor. Editor and language are two separate things. According to documentation, the code I posted is the proper way to change editor status of class properties. Appearance of custom properties can be controlled via @export but for properties inherited from built-in classes I think there's no other way except maybe creating shadow custom properties solely for purpose of tracking, which is imho much clumsier and bug prone than this.

                Inside a Script, _get_property_list may be overridden to customize properties in several ways. This allows them to be available to the editor, display as lists of options, sub-divide into groups, save on disk, etc. Scripting languages offer easier ways to customize properties, such as with the @GDScript.@export annotation.

                I'm not sure why they chose velocity to be invisible by default though. Maybe it's an oversight because this property was added in v 4. If you think this is the case - report the issue on Godot's github.

                Btw GDScript, similarly to Python has no concepts of public, protected or friend members/classes. Everything is public, although, again, member publicity and editor visibility have nothing to do with each other.