Hey,
I needed similar thing and managed to find a solution.
It turns out, that UE4 has spectator functionality built-in. It’s just not properly documented and advertised.
There’s a set of functions that allows you to cycle through players if you are curently spectating.
I’m attaching the project that has this figured out. I’ve tried it on GearVR and PC. GearVR was acting as a server (so that spectating functionality is optional).
By default the game loads an entry map, that immediately chainloads another map but with ?listen
parameter to make sure that the game starts as a listen server.
Next, you can connect from PC with another instance of the game:
cd C:\Program Files\Epic Games\4.10\Engine\Binaries\Win64
UE4Editor.exe C:\Path\to\project\NetTest.uproject 10.0.0.5?SpectatorOnly=1 -game
Replace path and ip accordingly. The SpectatorOnly=1
causes the player to immediately become a spectator (Look at AGameMode::Login()
).
After you connect, press PageUp and PageDown to cycle through players, and Home to go back to free
flight camera (in this example it’s quite limited becuase it’s set up for mobile controls).
Relevant logic (not much of it) is implemented in Content\FirstPersonBP\Blueprints\Spectator
asset and in
ANetTestPlayerController
class.
Effectively, spectator functionality is implemeted as changing the view target in PlayerController/PlayerCameraManager ( APlayerController::SetViewTarget()
).
If you have more questions, feel free to ask.
Link to example: