Skip to content

Can't return typed arrays from C# functions to GDScript #100070

Open
@TheSecondReal0

Description

Tested versions

Reproducible in 4.4dev5

System information

Windows 10, Godot v4.4dev5

Issue description

If I declare a function in C# like this:

public Godot.Collections.Array<Vector2> GetCoolPlaces() {
    return new Godot.Collections.Array<Vector2>(... some values);
}

I would expect to be able to put the result into a typed array variable in GDScript:

var cool_places: Array[Vector2] = CSharpObject.GetCoolPlaces()

But the above code will result in this runtime error:
Trying to assign an array of type "Array" to a variable of type "Array[Vector2i]".

It is possible to do by creating a new typed array from the result of the function like this:

var cool_places: Array[Vector2] = Array(CSharpObject.GetCoolPlaces(), TYPE_VECTOR2, "", null)

But this is really clunky and annoying to do, especially when it's a function you use often.

Note: Packed arrays would not be a solution here, as this is also a problem for custom classes (e.g. Resources).

Steps to reproduce

Create a function in C# that returns an array and try to put the result of that function into a typed array in GDScript. See MRP for example

Minimal reproduction project (MRP)

Reproduce by running this project:

CSharp Typed Arrays.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions