#Events subscribe twice?

5 messages · Page 1 of 1 (latest)

scarlet vine
#

Hi, I was following the wiki on custom networking and more or less have the exact layout as follows:

[HarmonyPostfix, HarmonyPatch(typeof(RoundManager), nameof(RoundManager.GenerateNewLevelClientRpc))]
static void SubscribeToHandler()
{
    ExampleNetworkHandler.LevelEvent += ReceivedEventFromServer;
}

[HarmonyPostfix, HarmonyPatch(typeof(RoundManager), nameof(RoundManager.DespawnPropsAtEndOfRound))]
static void UnsubscribeFromHandler()
{
    ExampleNetworkHandler.LevelEvent -= ReceivedEventFromServer;
}

But the SubscribeToHandler() subscribes twice for some reason on the host. It subscribes just once if it's just a client and NOT the host. Since that happens, I suspect it's a problem with differentiating those two...

I've tried putting an if statement inside "SubscribeToHandler()" that filters on like "!NetworkManager.Singleton.IsHost" and "!RoundsManager.Instance.IsHost" and other iterations checking if it's JUST the client then subscribe once, but it doesn't work ofc

stuck atlas
#

i know there is a field for .isHost which is present in a lot of server handling stuff, check if you can diend that in your current context and maybe then add an if statement in the function that returns if isHost == true

#

worth a try but i have no experience with any serverside stuff tho so this is just a possible lead for you

scarlet vine
#

any idea is really appreciated and I'll try that, thanks 👍

crisp pawn
#

hmm, I'll look into it. This wasn't happening to me before, seems like something changed in v45 that causes it to be called twice