DemoPlay can't spawn custom spectator class

Hi,

I’m on version: Version: 4.8.3-0+++depot+UE4-Releases+4.8
with the github source.

I reckon the demo (demorec, demoplay, etc) is still in it’s infant’s shoes.

I’m binding to the PostDemoPlay delegate like so:

void UMyLocalPlayer::PostInitProperties()
{
    Super::PostInitProperties();
    
    FCoreUObjectDelegates::PostDemoPlay.AddUObject(this, &UMyLocalPlayer::DemoStarted);
}

The difficulty here is that obviously the demoplay command doesn’t allow specifying a custom playercontroller class. It simply spawns the PendingLevelPlayerControllerClass in ULocalPlayer::SpawnPlayActor(…) called from UWorld::LoadMap(…) (LoadMap is called by: UDemoNetDriver::InitConnectInternal(…)).
Even though there exists a UDemoNetDriver::DemoSpectatorClass which can be specified via config, this is not used when setting up a demoplay PlayerController.

Now, trying to spawn my own MyPlayerController class after PostDemoPlay has been broadcasted, it simply fails because the UWorld I receive from ULocalPlayer::GetWorld() doesn’t have a CurrentLevel:

AActor* UWorld::SpawnActor( UClass* Class, FVector const* Location, FRotator const* Rotation, const FActorSpawnParameters& SpawnParameters )
{
	SCOPE_CYCLE_COUNTER(STAT_SpawnActorTime);
	check( CurrentLevel );       // CurrentLevel is NULL here!!!
	check(GIsEditor || (CurrentLevel == PersistentLevel));
        ...
}

Also:

void UMyLocalPlayer::DemoStarted()
{
    GetGameInstance()->GetWorld()->SpawnActor<AMyPlayerController>(AMyPlayerController::StaticClass());
}

yields the same error.

I currently find no way of spawning my own spectator PlayerController class in a demoplay environment.

According forum thread: Spawning actor during demoplay - C++ - Epic Developer Community Forums

Hi ,

It is possible to use your own PlayerController class for this, but it has to be known when the replay is recorded, so that an actor of this type can be spawned and recorded in the replay. Also, the way you specify this class has changed in 4.9.

In 4.9, you’ll need to set the ReplaySpectatorPlayerControllerClass property on the GameMode class.

In 4.8, the class is set through the config property DemoSpectatorClass on UDemoNetDriver. You can add a line like the following to your DefaultEngine.ini file (this one is from ShooterGame):

[/Script/Engine.DemoNetDriver]
DemoSpectatorClass=ShooterGame.ShooterDemoSpectator

ShooterGame uses a custom spectator controller for replays, so feel free to use it as an example!

Ah, well that makes sense! Thanks a ton for your reply, Ryan. Really looking forward to the 4.9 version, especially in respect to Broadcasting a match to huge amount of spectators (in-game) - Multiplayer & Networking - Epic Developer Community Forums .