Skip to content

rainbow-duck-games/unity-entity-signals

Repository files navigation

Unity Entity Signals

Unity Tests status Install with OpenUPM Follow Twitter Join Discord

This project is an evolution of the library widely used in our projects Pixeye Signals. However usign the library we found that we want something much more flexible to handle our cases. So we took best parts of the lib and created the new one.

The Idea

Everything is our projects were binded to one or another entities and we widely used signals to communicate entities changes between components. First we used signals with entity reference inside, but the approach caused a giant collection of handlers which started to be inefficient. After we started to create a new signals instance inside every entity, but this turns out to be a mess of possible places to subscribe / send signals & caused some problems with generic messages.

All these problems triggered the development of this library. We also tried to achieve following targets:

  • Strict type as much as possible
  • Easy to debug and isolate
  • Entity-related handlers
  • Extendability
  • Dynamic entity matching (in plans)
  • Strict mode (in plans)
  • Verbose mode (in plans)

Base usage

Install the package using OpenUPM

Entity related handler

var es = new EntitySignals();
var entity = new TestEntity();
var handler = (ESHandler<TestEntity, int>) ((entity, i) => { /* Something useful here */ });

es.On(entity).Add(handler);
es.On(entity).Send(1);

Type related handler

var es = new EntitySignals();
var entity = new TestEntity();
var handler = (ESHandler<TestEntity, int>) ((entity, i) => { /* Something useful here */ });

es.On<TestEntity>().Add(handler);
es.On(entity).Send(1);

For detailed documentations check README.md

FAQ

  • I have problems with MacOS / WebGL build. The project doesn't work at all!

    Most probably the issue is related to IL2CPP implementation in Unity. You can check this issue to find more details and links, but to fix the issue you have to add link.xml file in the root Assets folder with following content:
    <linker>
      <assembly fullname="System.Core">
        <type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
      </assembly>
    </linker>
    

Contribution

We are welcome any contribution. Feel free to create issues, start a discussion or even fork and create a pull request. If you are looking for some advice or hints also consider to join our Discord Server

Links & References

  • Pixeye Signals - The original library we used, also used as a reference for performance testing
  • Tact.Net - Used as part of this lib to optimize delegates calls. You can find it in Utility/Tact