timit0
February 2, 2024, 8:27am
1
Godot Version
4.2
Question
I have an error with [Export] attribut.
The game crash before start.
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
timit0
February 7, 2024, 12:10pm
3
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.
te1ny
February 8, 2024, 9:38am
5
I think get/set is unnecessary in this case, because initially get/set is implied when creating a variable.
te1ny
February 8, 2024, 9:41am
6
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; }
te1ny
February 8, 2024, 4:10pm
8
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
Moreus
February 8, 2024, 10:22pm
9
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.
Moreus
February 8, 2024, 10:41pm
10
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.
timit0
February 10, 2024, 6:09pm
11
I think line n°16 is an auto generated code
timit0
February 10, 2024, 10:35pm
12
Ok guys, I found my mistake it was that
I changed to that one and Itâs work.
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.
paulloz
February 11, 2024, 10:52am
13
Ah, yes, nice catch! For reference, the linked issue on GitHub:
opened 10:04AM - 09 Jan 23 UTC
bug
topic:dotnet
regression
### Godot version
v4.0.beta.mono.custom_build [56522f7f8] (with double)
##⊠# System information
Arch Linux, Vulkan
### Issue description
C# projects with a parent class including a virtual property that is then overridden & initialized in a child class appear to cause ScriptPropertiesGenerator & ScriptSerializationGenerator to fail to generate source.
The problem appears to be caused by #70483, the Source Generators run fine if built immediately before this PR was committed.
I'm not sure how to debug the Source Generators for a more useful error/stack trace than below, sorry.
### Parent Class
```cs
using Godot;
public partial class TestParentClass : RigidBody3D
{
public virtual int NodeType { get; set; } = 1;
}
```
### Child Class
If the initialized property override below is commented then the Source Generators work fine.
```cs
public partial class TestChildClass : TestParentClass
{
public override int NodeType => 10;
}
```
## Warnings/Errors produced
Warnings produced when a child class overrides the initialized property from its parent:
```
0>CSC: Warning CS8785 : Generator 'ScriptPropertiesGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'NullReferenceException' with message 'Object reference not set to an instance of an object.'
0>CSC: Warning CS8785 : Generator 'ScriptSerializationGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'NullReferenceException' with message 'Object reference not set to an instance of an object.'
```
Any `[Export]` properties then throw build errors as ScriptPropertiesGenerator failed:
```
0>csharpbug_03c26d6/Godot.SourceGenerators/Godot.SourceGenerators.ScriptPropertyDefValGenerator/Nothing_ScriptPropertyDefVal.generated.cs(9,33): Error CS0117 : 'Node.PropertyName' does not contain a definition for 'TestInt'
0>csharpbug_03c26d6/Godot.SourceGenerators/Godot.SourceGenerators.ScriptPropertyDefValGenerator/Nothing_ScriptPropertyDefVal.generated.cs(11,33): Error CS0117 : 'Node.PropertyName' does not contain a definition for 'TestFloat'
```
### Steps to reproduce
Build the solution in the minimal reproduction project.
### Minimal reproduction project
[csharpbug_03c26d6.zip](https://github.com/godotengine/godot/files/10371960/csharpbug_03c26d6.zip)
system
Closed
March 12, 2024, 10:52am
14
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.