Skip to main content

Messages Between Objects

TpMessages has a secondary, separate typed-subscription system using the same MessagePacket scheme.

Recall that messages to TPT tiles requires implementation of explicit interfaces,interfaces. Here, you need to subscribe to a typeType of message packet.

public static ulong RegisterMessageTarget<T>(Object? parent, Action<object> target) where T : MessagePacket<T>

You register your target to a particular variety of MessagePacket (which can be any arbitrary blob of data as long as the class is derived from MessagePacket. If the parent is UnityEngine.Object such as a Monobehaviour then null-checks ensure that if the Object becomes null then it is automatically deregisterd. Leave parent null when using a static class instance (which can't become null);

The target is an Action which receives a c# object which you have to cast back to the Type of the MessagePacket.

For example: