I created a source generator project by following Unity’s documentation on source generators, but when calling the ExampleSourceGenerated.ExampleSourceGenerated.GetTestText() method in Unity, I get a compilation error: Assets\Scripts\NewScript.cs(19,19): error CS0103: The name ‘ExampleSourceGenerated’ does not exist in the current context. Please tell me why this is failing (project source code at: GitHub - HarlingPI/SourceGeneratorTest: 源生成器测试项目)
In case someone encounters the same issue: For Unity 2022.3.13f1, the version number of the “Microsoft.CodeAnalysis.CSharp” package in the generator project should not exceed 4.3.1. With this version, the source generator in Unity 2022.3.13f1 can work properly.
1 Like