Skip to content

CSharp class is creatable in the scene without passing parameters. #1130

@Shadowblitz16

Description

@Shadowblitz16

Tested versions

v4.4 stable

System information

Debian 13

Issue description

CSharp classes that have the globalclass attribute and no parameter-less constructor are treated as if they have a parameter-less constructor.

Image
using Godot;
using System;

[GlobalClass]
public partial class Test : Godot.Node2D
{
    // This class doesn't have a parameterless constructor but godot is creating it without parameters.
	public Test(Vector2 position)
	{
		Position =position;
	}
}

This fix should probably be done for classes with generics too.

using Godot;
using System;

[GlobalClass]
public partial class Test<T> : Godot.Node2D
{
}

Generics actually error so they are less of a problem.

What should happen in both cases is either...

  1. A dialog comes up to pass in parameters and generics.
  2. The classes compiles fine and is shown but acts as a abstract class in the node dialog.
  3. They are clear compile time errors.

Of course abstract classes should be able to be parameterized and generic since they are never created.

Steps to reproduce

  • Download example project.
  • Open it.
  • Look at script.
  • Try to create it in scene.
  • It works fine but it's not constructed correctly.

Minimal reproduction project (MRP)

csharp-parameter-bug.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions