Godot Version
4.3
Question
i have the following scene:
-scene (Node)
----PointsCalculator (with attached the PointsCalculator.cs script) (Node)
----PointsDrawer (with attached the PointsDrawer.gd script) (Node2D)
i am trying to generate a few (x,y) points in the C# script and use the gdscript to draw them
PointsDrawer.gd script:
extends Node2D
var points_calculator
func _ready():
points_calculator = get_node(“/root/scene/PointsCalculator”)
if points_calculator:
print(“Successfully connected to PointsCalculator”) #i get this
if points_calculator.has_method(“GetPoints”):
print(“GetPoints method exists!”)
else:
print(“GetPoints method is missing!”) #i get this
else:
print(“Failed to connect to PointsCalculator”)print(“1”)
queue_redraw()
func _draw():
var points = points_calculator.GetPoints() #fails here with “Invalid call. Nonexistent function ‘GetPoints’ in base ‘Node (PointsCalculator.cs)’.”for point in points:
draw_circle(point, 5, Color(1, 0, 0)) # Red color circles with radius 5func _process(_delta):
queue_redraw()
PointsCalculator.cs script:
using Godot;
using System;
using System.Collections.Generic;public partial class PointsCalculator : Node
{
private List Points = new List();// Example function to calculate points (you can customize this). public void CalculatePoints() { GD.Print("3!"); Points.Clear(); for (int i = 0; i < 10; i++) { float x = i * 20; float y = (float)(50 + 30 * Mathf.Sin(i)); Points.Add(new Vector2(x, y)); GD.Print(i," -> ", x," - ", y); } GD.Print("4#"); } // Public method to get the points. public List<Vector2> GetPoints() { GD.Print("GetPoints method called"); return Points; } public override void _Ready() { // Calculate points when the node is ready. CalculatePoints(); GD.Print("2!"); for (int i = 0; i < 10; i++) { GD.Print(i, " -> ", Points[i]); } }
}
the various sanity check prints are actually called and the gdscript connects the PointsCalculator, but cant find the GetPoints Method. Even if i replace it with Points as public, the gdscript still can’t find the variable Points.
Can someone help?
thanks is advance