Roslyn code generator and ECS’s code‐gen pipeline

Hi all;

Im having some issues with Roslyn code generation and ECS ISystems. I have IComponentData with a specific attribute I would like to generate systems for dynamically. These systems would just watch this attributes components for change. I understand I could hardcode every single IComponentData with this behavior but we have hundreds. Everything works fine, except when SystemAPI.Query<>() is invoked I am getting the error:

InvalidOperationException: No suitable code replacement generated

I presume that the ecs gode gen pass didnt have ‘time’ to transform my generated code?

Any insight on how I can approach this differently or ensure which pass my roslyn code is generated in would be great.

Edit: I know the generated query works. I coded a test ISystem and it was fine.

Edit. I solved it by just making an editor script that watches AssetDatabase for IComponentData with the attribute and generate/remove the scripts in the editor. Would really love a runtime solution though.

On the same assembly, source generators do not know each other’s output. Each generator receives the same compilation context then run isolately.

SystemAPI depends on source generator and that generator can’t read into the output of your generator.

Currently, there is no way to schedule which generator should run after or before which generator. Roslyn team seems to be not interested in making it possible too.

That said. You can still generate your custom system using Roslyn source generator, just make sure that you don’t ever output code that uses SystemAPI. You should generate what SystemAPI generator is going to generate.

Thanks for the reply. That’s unfortunate news. Your last statement seems like a good solution where order of operations wouldnt matter, ill dive deeper into what SystemAPI is generating.