Component Listener is not working
See original GitHub issueHi, I’m following the example Match One to creating an Unique global component and also created Listener for it.
My code is like this:
My ScoreComponent :
using Entitas;
using Entitas.CodeGeneration.Attributes;
[Game, Unique, Event(false)]
public class ScoreComponent : IComponent {
public int value;
}
My ScoreSystem:
public class ScoreSystem : ReactiveSystem<GameEntity>, IInitializeSystem
{
private Contexts _contexts;
private IGroup<GameEntity> _scoreGroup;
public ScoreSystem(Contexts contexts) : base(contexts.game)
{
this._contexts = contexts;
}
public void Initialize()
{
_contexts.game.SetScore(0);
}
protected override void Execute(List<GameEntity> entities)
{
int newScore = entities.Count;
_contexts.game.ReplaceScore(_contexts.game.score.value + newScore);
}
protected override bool Filter(GameEntity entity)
{
return true;
}
protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context)
{
return context.CreateCollector(GameMatcher.AllOf(
GameMatcher.Bucket,
GameMatcher.BucketRemoved
));
}
}
And my ScoreController:
using Entitas;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreController : MonoBehaviour, IScoreListener
{
public Text scoreLabel;
private Contexts _contexts;
private Systems _systems;
void Start () {
Contexts.sharedInstance.game.CreateEntity()
.AddScoreListener(this)
;
}
public void OnScore(GameEntity entity, int value)
{
scoreLabel.text = "Score " + value;
}
}
In my tests, the system is working but OnScore in my Controller is not being called at all.
Where is the problem in my code?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
java - ComponentListener is not working
In here, the ComponentListener is not working properly because the action inside the method "ComponentMoved" is not happening.
Read more >Event listeners not working? 3 key areas to troubleshoot
Are your event listeners not working as you'd expect? Here are 3 key areas to troubleshoot to help you get everything triggering as...
Read more >How to Write a Component Listener
The Component listener is a listener interface for receiving component events. A component is an ... You do not get component-hidden or -shown...
Read more >Component Listener is not working · Issue #688
Hi, I'm following the example Match One to creating an Unique global component and also created Listener for it. My code is like...
Read more >Event Listeners in React Components
There are a couple of problems with the code above. You only want the event listener added when the component finishes rendering.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

have you put the
GameEventSystemsin your feature class ?but the Match One repo is using a old version of Entitas that the generated system named call
EventSystems. The lastest version will generate[ContextName]EventSystems.