Search Unity

Question Rpc's and circular referencing

Discussion in 'Netcode for GameObjects' started by cerestorm, Mar 30, 2022.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    660
    I have a Messenger class in the Messaging namespace that's meant to be a general purpose class that sends and receives a message object of differing types. I use this class in a couple of other namespaces, Portal and Game.

    The issue I have is being able to send a message of a particular type where the Messenger class doesn't have to be explicitly made aware of the type of message it's sending, be it a PortalMessage or a GameMessage. Being aware means there's a circular namespace dependency due to Messenger needing to use the Portal and Game namespaces to recognise these message classes.

    Is there any way around this? I'm currently using a Message class to handle all messages but because it contains an interface field I'm stuck with the same circular reference to identify the implementing classes.