Entitas
Entitas copied to clipboard
EntityIndex is not generated on non IComponent component
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
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