question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component Listener is not working

See original GitHub issue

Hi, 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
roygearcommented, Apr 24, 2018

have you put the GameEventSystems in your feature class ?

public sealed class GameSystems : Feature {

    public GameSystems(Contexts contexts) {

        // Input
        Add(new InputSystem(contexts));

        // Update
        Add(new GameBoardSystems(contexts));
        Add(new ScoreSystem(contexts));

        // Events
        Add(new GameEventSystems(contexts)); <-------------this

        // Cleanup
        Add(new DestroyEntitySystem(contexts));
    }
}
3reactions
roygearcommented, Apr 24, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found