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#: When using nullable reference types, show node configuration warning when there is an exported unset non-nullable reference type variable #8349

Open
nicolasgustafsson opened this issue Nov 4, 2023 · 2 comments

Comments

@nicolasgustafsson
Copy link

Describe the project you are working on

Mid-sized action platformer.

Describe the problem or limitation you are having in your project

Many nodes require references to resources or other nodes, but it is easy to miss them without a warning.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

A node configuration warning would be shown when an exported variable is not set(and it is not annotated with a ?) while having the flag set to true in the project settings.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

image
image

I am unsure of how technical implementation of this would look.

If this enhancement will not be used often, can it be worked around with a few lines of script?

You may override GetConfigurationWarnings, but it's equally easy to forget to do it, and adds boilerplate. This would be ideally be automatically used for all custom nodes.

Is there a reason why this should be core and not an add-on in the asset library?

I believed that it's impossible to do through an add-on.

@Calinou
Copy link
Member

Calinou commented Nov 6, 2023

@tvardero
Copy link

tvardero commented Apr 25, 2024

Note: [Export] private PackedScene JumpFx = null!; will only be non-nullable, if you have nullable context enabled in your project (in csproj file) or in this file (with #nullable compiler directive).

By default, new Godot projects does not have nullable context enabled. User needs to enable it manually. Related: #8475

Prior to .Net 6, detecting if a reference type is marked as nullabe was cumbersome. (No, Nullable.GetUnderlyingType(type) works for value types only.)
Starting with .Net 6, we have NullabilityInfoContext to check the thing at runtime.

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

No branches or pull requests

3 participants