Thank you for reaching out with your issue, krizzl0r. It sounds like there is a regression in the Needle Engine component generator in version 4.16.0 that is causing the changes you’ve observed. Let’s clarify and address your concerns step by step:
Understanding the Regression
-
Public Methods Returning a Promise:
- Before: Your method
start was being generated as void, but now it is generating public Promise Start() in C#.
- After: The method signature now includes
async and Promise, which is causing issues with the C# compiler.
-
Implementing IEditorModification:
- Before: The methods
onEditorModification and onAfterEditorModification were being generated as void methods, even though they are web-only and should not be accessible from C#.
- After: The generation now includes the
EditorModification parameter, which is not available in C#.
-
Using Other Web-Only Types:
- Before: These methods were being stripped of their
bar type, which was web-only.
- After: Now, the type
Bar is being included in the generated C# method, causing issues with type mismatch and the C# compiler.
Solution Approach
From the documentation and your examples, it appears that the C# generator is now more strict about what is generated and may be including type information that isn’t compatible with C#.
Option 1: Opt-Out for Methods and Properties
You can use the // @dont-generate-component comment to skip generating C# components for specific classes or methods.
export class MyComponent extends Behaviour {
// @dont-generate-component
override async start(): Promise<void> {
// ...
}
// @dont-generate-component
onEditorModification(modification: EditorModification): void | undefined | boolean { return false; }
onAfterEditorModification?(mod: EditorModification): void {
// ...
}
async doStuff(bar: Bar): Promise<any> {
// ...
}
}
This will ensure that the methods and their associated properties are not included in the generated C# component.
Option 2: Replace Unavailable Types with Object or void
Alternatively, you can use the // @type comment to replace web-only types with Object or void where needed.
export class MyComponent extends Behaviour {
// @type Object
onEditorModification(modification: any): void | undefined | boolean { return false; }
onAfterEditorModification?(mod: any): void {
// ...
}
// @type void
async doStuff(bar: any): Promise<void> {
// ...
}
}
This will instruct the generator to treat EditorModification and Bar as Any types in C#, which should resolve the compilation issues.
Clarifying Your Needs
-
Visibility and Accessibility:
- Do you specifically need these methods to remain accessible only in TypeScript? If so, use the
// @dont-generate-component comment.
- If you need to access these methods from Unity components or other C# scripts, provide the
// @type Object comment for web-only types.
-
Version Control:
- It’s a good practice to check in generated C# components in version control. This allows you to revert or manage changes in the future.
Further Steps
- Save the TypeScript File:
- Ensure you save the changes to your
.ts file.
- Component Generation:
- The generator should now produce the correct C# stubs in
Assets/Needle/Components.codegen/.
- Verify that the C# component appears in Unity’s Add Component menu and can be attached to Game Objects.
Conclusion
Given the regression, either opting out the methods or replacing the web-only types with Object or void should solve your build issues. If you continue to face problems, feel free to provide more details or examples, and we can further refine the solution.
Sources: Needle Engine Docs (59%), Needle Engine Docs (57%), Needle Engine API (56%), Needle Engine Docs (56%), Needle Engine Docs (55%), Needle Engine Docs (55%), Needle Engine Docs (55%), Needle Engine Docs (55%), Needle Engine Docs (55%)
1 replies left - Become PRO for more replies.
Reply to this post directly if you need further help (bottom right button)