Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Exported Array<Node> is null #97190

Open
LasseSchnepel opened this issue Sep 19, 2024 · 3 comments · May be fixed by #97864
Open

C# Exported Array<Node> is null #97190

LasseSchnepel opened this issue Sep 19, 2024 · 3 comments · May be fixed by #97864

Comments

@LasseSchnepel
Copy link

Tested versions

4.3 stable

System information

Godot v4.3.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1070 Ti (NVIDIA; 31.0.15.3623) - AMD Ryzen 7 2700X Eight-Core Processor (16 Threads)

Issue description

I have a larger project, that uses C# for all the scripts. Everything works fine when I start the game from the editor. When I export it, I get several errors, that I was able to trace back to that an exported variable is null, instead of being set to the value that is stored in the scene.
This applies to exported variables, that are made of a Godot.Collections.Array, where can be Node or any other Script that inherits from Node.
If I replace the Array with Node[], the export is working fine.

Steps to reproduce

Unfortunately, I was not able to create a MRP, as the issue did not persist in a minimal project. So unfortunately, I do not know how to reproduce, but I can share the code with one or two people who want to investigate the issue.

Minimal reproduction project (MRP)

I was not able to create a MRP and don't want to publically share my project, but I can share the code with one or two persons who want to investigate the issue.

@AThousandShips
Copy link
Member

but I can share the code with one or two persons who want to investigate the issue.

This will not work, if you are unable to reproduce this in a new project an MRP is going to be necessary, so please try to create one, or this won't be possible to test

@LasseSchnepel
Copy link
Author

Hi @AThousandShips,
Yes, I understand that. While I was not able to reproduce a MRP from scratch, I now tried to strip everything from my project and I think I have a quiet minimal example now.

While stripping it down and, I realized that there are multiple scenarios, which all behave different:

  • If the problematic scene (Level.tscn) is the starting scene:
    the editor removes the value of the problematic property from the tscn (checked via texteditor/git). I think this is done because the C# project is not build at that time. I don't think it's good that this is done. For this case, I would even understand that the problematic property is then zero.
  • If the problematic scene is not the starting scene:
    the problematic scene file (Level.tscn) is unchanged, but the export shows the same problem. If I (after export) open the Level.tscn, the value of the property is removed
  • If the problematic scene is not the starting scene:
    And the first thing I do in the editor is to open the Level.tscn, it removes the value of my property.
  • If the problematic scnee is not the starting scene:
    And the first thing I do in the editor is to build the project (not start), then I can open the Level.tscn without losing the value of the property, also an export is then working fine. In this case, the export is also fine if I do it directly after building the project (without opening Level.tscn)

So, I would sum it up as:
C# Properties (maybe only Array) are being removed from the .tscn file if the scene is opened before the project is build for the first time.

I hope this helps, please find the MRP attached:
mrp.zip

@AThousandShips
Copy link
Member

That should hopefully help! Thank you! Can't test C# projects myself at the moment but I'm sure someone will take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants