How do you tell what a var in GDScript is referencing?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By laterdated

I am trying to convert a script from GDScript into C#, but I’m having a difficult time finding out what a var is referencing.

Here’s a part of the script I’m trying to convert.

    onready var collision_shape = get_node("KinematicBody/CollisionShape")
    collision_shape.shape.radius = player_radius
    collision_shape.shape.height = camera_height - player_radius
    collision_shape.transform.origin.y = (camera_height / 2.0)

Here’s how I am converting it.

private CollisionShape collisionShape;
collisionShape = (CollisionShape)GetNode("KinematicBody/CollisionShape");
collisionShape.shape.radius = playerRadius;
collisionShape.shape.height = cameraHeight - playerRadius;
collisionShape.transform.origin.y = (cameraHeight / 2.0f)

However I’m getting an error.

‘CollisionShape’ does not contain a definition for ‘shape’

I’m not sure what I should be converting collisionShape into. Is there anyway to see what a var type of object a var is referencing?

:bust_in_silhouette: Reply From: Icaro-Lima

I can’t test here now, but with the little knowledge I have about C#, try this:

Ref: API differences to GDScript — Godot Engine (3.1) documentation in English “As explained in the Introduction, C# generally uses PascalCase instead of the snake_case used in GDScript and C++.”

I understand that, maybe I didn’t make my problem clear. In GDScript you can get the node of a mesh like this.

var hand_mesh = $Hand

However, when I try this in C# by doing this:

private Mesh handMesh;
handMesh = (Mesh) GetNode("HandMesh");

I get an error for trying to declare handMesh with GetNode. It says that a Node cannot be converted to a Mesh. Does this mean that the hand_mesh in GDScript isn’t actually referencing a mesh? If so, what do I make my handMesh in C#?

laterdated | 2019-12-17 03:12

Try this:

private MeshInstance handMesh;
handMesh = (MeshInstance) GetNode("HandMesh");

Mesh != MeshInstance

Ícaro Dantas de Araú | 2019-12-17 07:32