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