What is the replacement in c# for GD script ":="?

Godot Version

4.2

Question

What is the replacement in c# for GD script for like like this
Which creates Node3D from string path like:

`var Player := “/root/World/NavigationRegion3D/Player”

What is the C# equivalent ? `
Thanks

This does not create a ‘Node3D’.
This creates a string:

	var player := "/root/World/NavigationRegion3D/Player"
	print(player is String)

Outputs ‘true’

I think you must have meant:
var player := $World/NavigationRegion3D/Player

I don’t C# with GODOT but I would be very surprised if there was type inference similar to ‘:=’ since C# is a strictly typed language.

1 Like
using Godot;
public partial class MyTest : Node2D {
	Node2D m_node = null;
	Node2D m_node_2 = null;
	public override void _Ready() {
		
		// load the scene
		var v_scene = GD.Load<PackedScene>("res://sprite.tscn");


		// create two instasnces
		// NOTE: root node of sprite.tscn scene is node2d
		m_node = v_scene.Instantiate<Node2D>();
		m_node_2 = v_scene.Instantiate<Node2D>();

		// add instances as children of current node
		CallDeferred("add_child", m_node);
		CallDeferred("add_child", m_node_2);
	}
	public override void _Process(double delta) {
		// position on mouse - 100px
		m_node.GlobalPosition = GetGlobalMousePosition() + new Vector2(-100, 0);

		// position second node on mouse + 100px
		m_node_2.GlobalPosition = GetGlobalMousePosition() + new Vector2(100,0);
	}
}

problem that player is not scene file , its CharacterBody3D

what exactly are you trying to do?

Ok i found the answer :
Player = GetNode(“/root/World/player”);