Multicast Invalidates Blueprint References (or something, it's weird)

As you can see here

SpectatorPawn and HUD exist only on owning client.

The HUD is not something you want to check on the server since it doesn’t exist there!
You probably want to create an event dispatcher in the Game State and call it from the server function (if you want things to happen in every client).
You can subscribe to it from where you need it (the HUD for example) and bind an event to toggle things.


Steps:

  • Create a custom game state and assign it in the game mode
  • Create an event dispatcher in the game state with a boolean parameter (so you can call on and off with the same event)
  • Create an event in the game state (with a bool too) and call the event dispatcher from there

In the player controller:

  • Get the game state and cast it to your custom child class (save it to a variable if you want to avoid other gets and casts in future)
  • Call the event when you need it in a server function.

In the HUD:

  • In BeginPlay Get the game state and cast it to your custom child class (save it to a variable if you want to avoid other gets and casts in future), assign the event dispatcher to a custom function to toggle the widget
2 Likes