jeffcampbellmakesgames / Entitas-Redux

An entity-component framework for Unity with code generation and visual debugging
MIT License
102 stars 13 forks source link

[BUG] Indexes are not generated #53

Closed miroslavzeman closed 3 years ago

miroslavzeman commented 3 years ago

Describe the bug Attributes [EntityIndex] and [PrimaryEntityIndex] do not generate additional code for getting entities from context.

Unity Version: Unity 2020.3.0f1

To Reproduce

  1. Create new Unity 2020.3.0f1 project
  2. Update manifest.json with:
    "com.jeffcampbellmakesgames.genesis": "https://github.com/jeffcampbellmakesgames/genesis.git#release/stable",
    "com.jeffcampbellmakesgames.entitasredux": "https://github.com/jeffcampbellmakesgames/entitas-redux.git#releases/stable"
  3. Setup genesis based on documentation -> click on Update Genesis CLI and Install or Update All Plugins
  4. Create GenesisSettings and click on Auto Import
  5. Create a class with content for testing the attributes:
using JCMG.EntitasRedux;

[Game]
public class PrimaryComponent : IComponent
{
    [PrimaryEntityIndex]
    public int value;
}

[Game]
public class SecondaryComponent : IComponent
{
    [EntityIndex]
    public int value;
}

public class Controller
{
    public Controller()
    {
        var context = new Contexts();
        // should contain something like: context.Game.GetEntityWithPrimary
        // should contain something like: context.Game.GetEntitiesWithSecondary
    }
}
  1. Generate code via Generate button in GenesisSettings or shortcut CTRL+SHIFT+G

Expected behavior Methods for getting data by indexes should be present in Game context, but they are not. It's not possible to use methods like context.Game.GetEntityWithPrimary() etc.

Screenshots

Genesis settings: image

Genesis setup in project settings: image

Additional context Win 10, using Mono .NET 4.x in Unity player settings

jeffcampbellmakesgames commented 3 years ago

I was able to track down and reproduce this bug locally. I was able to inspect further and have a feeling I know what the error is. I should have some more info in a day or two as to a fix.

jeffcampbellmakesgames commented 3 years ago

Looking at the implementation of EntityIndexDataProvider.cs here, it appears to be checking for any members of a component decorated with inherited attribute types of AbstractEntityIndexAttribute. However the extension/helper methods for HasAttribute and GetAttributes do not check base classes of attributes. As a result it would never find the Primary or Entity index attributes which derive from AbstractEntityIndexAttribute.

To resolve this I am approaching this as a few steps:

jeffcampbellmakesgames commented 3 years ago

I've completed the first step of this which was to update genesis with better functionality for checking inherited attributes. Released this morning as a part of Genesis v2.3.1. I'll be taking a look at the data provider either tomorrow or this weekend.

jeffcampbellmakesgames commented 3 years ago

Just wanted to share an update on this; I have a fix prepared and am tracking down a remaining issue. I should have a new version containing this fix available mid-week.

jeffcampbellmakesgames commented 3 years ago

I've fixed this issue and merged to develop, the fix for this should soon be available in Entitas-Redux v2.1.0. If you could retest on this new version and let me know if this resolves your issue, I'd appreciate it.

miroslavzeman commented 3 years ago

Working like a charm! 💯 Thank you! 👍