C# Error with [Export] attribut

Godot Version

4.2

Question

I have an error with [Export] attribut.
The game crash before start.
Capture d’écran 2024-02-02 092246

This is CS0117 error.
If anyone know the resolve please help me.

There has to be other errors when you are trying to build (it should say something along the lines of “this generator won’t contribute to the output”).

1 Like

Yes, you know how to resolve this error?

This means something in your code unexpected by Godot’s source generators, it’s hard to tell you what without seeing the sources.

If this started recently, you could step through what changed between your last working version and the current failing one.

I think get/set is unnecessary in this case, because initially get/set is implied when creating a variable.

You can try duplicating variables and giving them a different access modifier.
My example:

private float maxHealth = 10;

[Export]
public float MaxHealth
{
	get
	{
		return maxHealth;
	}
	private set
	{
		maxHealth = value;

		if (CurrentHealth > maxHealth)
		{
			CurrentHealth = maxHealth;
		}
	}
}

That is a bit misleading. One would define a field, the other an auto-implemented property.

// This is a field.
public string SomeText;

// This is an auto-implemented property.
public string SomeOtherText { get; set; }

Of course, I don’t know C# very well, but I think that in this context of the task it is not necessary to use the auto-realizable property

Properties are more flexible and secure than variables. In the future, you may want to validate your data in a setter, and all functions using that property will not break. With variables, if you want to achieve something similar without breaking your code in the future, all your variables need to be private and have getters and setters.

I don’t really see why your code doesn’t compile. We don’t see your full code. All nodes already have a Name property, so there’s no problem using them instead of making new ones. Your property should start with a capital letter. You’re getting ‘
’ to fix that. Is your error on line 16? We don’t see your code line numbers.

I think line n°16 is an auto generated code

Ok guys, I found my mistake it was that

error

I changed to that one and It’s work.

solution

The error was just the setter was missing.
But it was long to find.

Thanks to all the guys who put me on the right path.

:grin::grin:

Ah, yes, nice catch! For reference, the linked issue on GitHub:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.