GD0002: Missing partial modifier on declaration of type which contains nested classes that derive from GodotObject

Rule ID

GD0002

Category

Usage

Fix is breaking or non-breaking

Non-breaking

Enabled by default

Yes

Cause

A type that derives from GodotObject is contained in a non-partial type declaration.

Rule description

Godot source generators add generated code to user-defined types to implement the integration with the engine. Source generators can’t add generated code to types that aren’t declared partial.

  1. public class InvalidParentType
  2. {
  3. // MyNode is contained in a non-partial type so the source generators
  4. // can't enhance this type to work with Godot.
  5. public partial class MyNode : Node { }
  6. }
  7. public partial class ValidParentType
  8. {
  9. // MyNode is contained in a partial type so the source generators
  10. // can enhance this type to work with Godot.
  11. public partial class MyNode : Node { }
  12. }

How to fix violations

To fix a violation of this rule, add the partial keyword to the type declaration.

When to suppress warnings

Do not suppress a warning from this rule. Types that derive from GodotObject but aren’t partial can’t be enhanced by the source generators, resulting in unexpected runtime errors.


User-contributed notes

Please read the User-contributed notes policy before submitting a comment.

Previous Next