Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party [PUN2] UnityEvents and multiplayer

Discussion in 'Multiplayer' started by PascalTheDog, Jan 28, 2022.

  1. PascalTheDog


    Mar 16, 2015

    I have a simple zombie survival FPS setup, and I'd like to turn it into a multiplayer experience. I have the room management and player position sync up and working. Now is the time to have things like Health sync too.

    My architecture is heavy on UnityEvents. Take my Health class for instance: It does not deal with anything beyond the core health logic; what it does is use UnityEvents to send the appropriate information around in a loosely coupled fashion. When the Hurt method is called, both the OnHealthChange and OnHurt UnityEvents are invoked which I use to deal with all sorts of stuff like updating the GUI, playing sound effects, recording frag data, etc. All I have to do is drag 'n' drop the appropriate references in the Inspector.

    My Health RPCs seem to be working; if I shoot another player, they do receive the damage via the Hurt method RPC. The problem however is that the GUI on the receiver's side gets updated, but not on the other's. My OnHealthChange UnityEvent passes the current HP / max HP ratio as an argument and this is used to set the value of the healthbar slider within the 0-1 range, but nothing happens on the other player's side. It's as if the UnityEvent were not called there.

    I also use a nifty ScriptableObject-based, scene-independent event system (the one from Unite Austin 2017) for more global events such as OnMatchStart or OnMatchEnd. Is this going to be a problem? What's the best way to make this approach work in multiplayer?

    Assistance would be greatly appreciated. Cheers!