sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.08k stars 1.11k forks source link

Components not picked up by Roslyn code generator but by Jenny #962

Closed matthiashermsen closed 3 years ago

matthiashermsen commented 3 years ago

Hi, I sticked to the LTS version and followed the guide I've written some days before (lol)

https://github.com/sschmid/Entitas-CSharp/wiki/How-to-setup-a-new-Github-project-with-Unity-and-tests

For testing purposes I created these files

TestInitSystem.cs

using Entitas;

public sealed class TestInitSystem : IInitializeSystem
{
    private readonly Contexts contexts;

    public TestInitSystem(Contexts contexts)
    {
        this.contexts = contexts;
    }

    public void Initialize()
    {
        contexts.game.CreateEntity();
    }
}

TestFooFeature.cs

public sealed class TestFooFeature : Feature
{
    public TestFooFeature(Contexts contexts)
    {
        Add(new TestInitSystem(contexts));
    }
}

GameController.cs

using UnityEngine;

public class GameController : MonoBehaviour
{
    private TestFooFeature testFooFeature;

    void Start()
    {
       Contexts contexts = Contexts.sharedInstance;
       testFooFeature = new TestFooFeature(contexts);
       testFooFeature.Initialize();
    }

    private void Update()
    {
        testFooFeature.Execute();
    }
}

After running

mono Jenny.exe gen

the generated code works fine in Unity. During playtime the entity got created by the init system.

When creating a new component

TestFooComponent.cs

using Entitas;

[Game]
public sealed class TestFooComponent : IComponent
{
    public string value;
}

and regenerating the sources this component was not picked up by the Roslyn code generator. So first of all I can't add the component to the generated entity during playtime in the inspector

image

Next it's not possible for me to add this component to entities via code, so this can't be resolved

GameEntity entity = contexts.game.CreateEntity();
entity.AddTestFoo("bar");

When I go to Tools => Jenny => Generate the sample works fine, so the component got picked up and I can add it via code. When running the Roslyn code generator again, it will remove the picked up component, so the code can't be resolved anymore

image

When I check the generated folder there is a directory called "Components" but it's empty when using Roslyn. When using the default code generator the component exists in that directory.

What am I missing? I think it's a really stupid mistake but it's important to know so I can update the written guide in the Wiki.


It seems my Jenny.properties file is not correct. This is how I setup the Roslyn generator

https://github.com/sschmid/Entitas-CSharp/wiki/How-to-setup-a-new-Github-project-with-Unity-and-tests#optional-setting-up-the-roslyn-code-generator

And finally these are my properties

Jenny.SearchPaths = Assets/Libraries/Entitas/DesperateDevs/Editor/Plugins, \
                    Assets/Libraries/Entitas/Entitas/Editor/Plugins, \
                    Jenny/Plugins/Entitas.Roslyn

Jenny.Plugins = DesperateDevs.CodeGeneration.Plugins, \
                DesperateDevs.CodeGeneration.Unity.Plugins, \
                Entitas.CodeGeneration.Plugins, \
                Entitas.Roslyn.CodeGeneration.Plugins, \
                Entitas.VisualDebugging.CodeGeneration.Plugins

Jenny.PreProcessors = DesperateDevs.CodeGeneration.Plugins.ValidateProjectPathPreProcessor, \
                      DesperateDevs.CodeGeneration.Plugins.TargetFrameworkProfilePreProcessor

Jenny.DataProviders = Entitas.CodeGeneration.Plugins.ComponentDataProvider, \

Jenny.CodeGenerators = Entitas.CodeGeneration.Plugins.ComponentContextApiGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentEntityApiGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentEntityApiInterfaceGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentLookupGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentMatcherApiGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextAttributeGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextMatcherGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextsGenerator, \
                       Entitas.CodeGeneration.Plugins.EntityGenerator, \
                       Entitas.CodeGeneration.Plugins.EntityIndexGenerator, \
                       Entitas.CodeGeneration.Plugins.EventEntityApiGenerator, \
                       Entitas.CodeGeneration.Plugins.EventListenerComponentGenerator, \
                       Entitas.CodeGeneration.Plugins.EventListenertInterfaceGenerator, \
                       Entitas.CodeGeneration.Plugins.EventSystemGenerator, \
                       Entitas.CodeGeneration.Plugins.EventSystemsGenerator, \
                       Entitas.VisualDebugging.CodeGeneration.Plugins.ContextObserverGenerator, \
                       Entitas.VisualDebugging.CodeGeneration.Plugins.FeatureClassGenerator, \
                       Entitas.Roslyn.CodeGeneration.Plugins.CleanupSystemGenerator, \
                       Entitas.Roslyn.CodeGeneration.Plugins.CleanupSystemsGenerator

Jenny.PostProcessors = DesperateDevs.CodeGeneration.Plugins.AddFileHeaderPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.CleanTargetDirectoryPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.MergeFilesPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.NewLinePostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.UpdateCSProjPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.WriteToDiskPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.ConsoleWriteLinePostProcessor

Jenny.Server.Port = 3333
Jenny.Client.Host = localhost
DesperateDevs.CodeGeneration.Plugins.ProjectPath = Assembly-CSharp.csproj
Entitas.CodeGeneration.Plugins.Assemblies = Library/ScriptAssemblies/Assembly-CSharp.dll
Entitas.CodeGeneration.Plugins.Contexts = Game, \
                                          Input

Entitas.CodeGeneration.Plugins.IgnoreNamespaces = false
DesperateDevs.CodeGeneration.Plugins.TargetDirectory = Assets/Sources

Jenny.CodeGenerators = Entitas.CodeGeneration.Plugins.ComponentContextApiGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentEntityApiGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentEntityApiInterfaceGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentLookupGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentMatcherApiGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextAttributeGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextMatcherGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextsGenerator, \
                       Entitas.CodeGeneration.Plugins.EntityGenerator, \
                       Entitas.CodeGeneration.Plugins.EntityIndexGenerator, \
                       Entitas.CodeGeneration.Plugins.EventEntityApiGenerator, \
                       Entitas.CodeGeneration.Plugins.EventListenerComponentGenerator, \
                       Entitas.CodeGeneration.Plugins.EventListenertInterfaceGenerator, \
                       Entitas.CodeGeneration.Plugins.EventSystemGenerator, \
                       Entitas.CodeGeneration.Plugins.EventSystemsGenerator, \
                       Entitas.VisualDebugging.CodeGeneration.Plugins.ContextObserverGenerator, \
                       Entitas.VisualDebugging.CodeGeneration.Plugins.FeatureClassGenerator, \
                       Entitas.Roslyn.CodeGeneration.Plugins.CleanupSystemGenerator, \
                       Entitas.Roslyn.CodeGeneration.Plugins.CleanupSystemsGenerator

Jenny.PostProcessors = DesperateDevs.CodeGeneration.Plugins.AddFileHeaderPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.CleanTargetDirectoryPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.MergeFilesPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.NewLinePostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.UpdateCSProjPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.WriteToDiskPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.ConsoleWriteLinePostProcessor

Jenny.Server.Port = 3333
Jenny.Client.Host = localhost
DesperateDevs.CodeGeneration.Plugins.ProjectPath = Assembly-CSharp.csproj
Entitas.CodeGeneration.Plugins.Assemblies = Library/ScriptAssemblies/Assembly-CSharp.dll
Entitas.CodeGeneration.Plugins.Contexts = Game, \
                                          Input

Entitas.CodeGeneration.Plugins.IgnoreNamespaces = false
DesperateDevs.CodeGeneration.Plugins.TargetDirectory = Assets/Sources

I think it should be this

Jenny.DataProviders = Entitas.CodeGeneration.Plugins.ContextDataProvider, \
                      Entitas.Roslyn.CodeGeneration.Plugins.CleanupDataProvider, \
                      Entitas.Roslyn.CodeGeneration.Plugins.ComponentDataProvider, \
                      Entitas.Roslyn.CodeGeneration.Plugins.EntityIndexDataProvider

but my file is lacking "Roslyn".


It seems I found the problem. When I run mono Jenny/Jenny.exe the CLI dialog opens up.

image

I then choose "Use jenny.properties". Until now I selected everything and executed "Save and continue (auto import)". But this seems to be wrong. What should be selected?

matthiashermsen commented 3 years ago

Closing in favor of #965