I’ve got a bunch of objects which use a UnityEvent to signal when their state has changed. In some cases, a change in one such object can trigger a change in another such object, causing it to invoke the same UnityEvent.
I have found that when this happens, the first invocation does not reliably complete. Specifically, any callbacks which should be called after the one which causes the UnityEvent to be re-invoked do not get called.
I at first assumed that I had an issue in my code and simply wasn’t handling the callbacks properly. After investigating this for a while I swapped the UnityEvent for a standard C# delegate, though, and the code worked exactly as intended - the state changes propagated as desired and other objects were also able to hook into the callbacks.
Is this a limitation in UnityEvent? A bug?
Specifically what I’m seeing is this:
I have objects A and B and C which are all listening for UnityEvent E. A invokes E (lets call this ‘E(A)’), which calls a function in B. In executing that function, B also invokes E (lets call this ‘E(B)’). E(B) calls functions in both A and C as expected. However, E(A) never calls C as expected.
In the above case A and B are of the same type, C is a different type, and E is a UnityEvent that belongs to a different class.