Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

EntityIndex is not generated on non IComponent component

Open andrumak opened this issue 8 years ago • 1 comments

Hi,

I use asset store version. This class produce component, but no EntityIndex

[CreateAssetMenu, Player]
public class MagicData : ScriptableObject
{
    [PrimaryEntityIndex] public int Index;
    ...
}

while this component generates fine along with player.GetEntityWithMagic method

[Player]
public class MagicComponent : IComponent
{
    [PrimaryEntityIndex] public int Index;
    ...
}

Is this intended behavior? I want to translate my SO settings into components. For now I create MagicData and Magic components side by side to get data with indexers together

Cheers

andrumak avatar May 10 '18 09:05 andrumak

Hi,

entity index only works on field of components.

But you can easily create you own custom entity index (example from the unit tests)

or even simpler, add a generic one directly to the contexts in the beginning of your app

        player.AddEntityIndex(new Entitas.PrimaryEntityIndex<PlayerEntity, int>(
            "Magic",
            game.GetGroup(PlayerMatcher.MagicComponent),
            (e, c) => ((MagicComponent)c).Index));

see https://github.com/sschmid/Match-One/blob/master/Assets/Sources/Generated/Contexts.cs#L67-L70

sschmid avatar Jun 07 '18 16:06 sschmid