Hi,
I did try to specify the outer, but still no luck.
I also tried to lower the timer period under the tick period (ie replaced 1.3f with 0.001f), but still nothing on screen.
Reading your discussion about chaining made me think i could create the FileServer from the wrong class (i must confess the NewObject function was called from a slate widget, and slate widget are quite mysterious beings for my poor newbie self), so i moved the whole stuff in the player controller. Still no luck.
Interestingly enough i tried to display the remaining time in the PC’s tick function, and i display nothing, which seems to indicate (see the condition in the following code) that the YagServerFile object is not valid somehow.
Here is the current code (still not working, the only message i get on screen is “UniqueHandle ACTIVE”):
Slate Widget.cpp:
FReply SYagOptionsWidget::CreateServer()
{
// get PC
AyagPlayerController* ThisPC = Cast<AyagPlayerController>(YagHUD->GetWorld()->GetFirstPlayerController());
if (!ThisPC) return FReply::Handled();
ThisPC->ConsoleCommand("open WelcomeMap?listen");
ThisPC->CreateAndStartFileServer();
return FReply::Handled();
}
-------------------------------------------------------------------------------------------------------
PlayerController.cpp:
void AyagPlayerController::CreateAndStartFileServer()
{
if (Role < ROLE_Authority) return;
YagFileServer = NewObject<UYagFileServer>(this);
YagFileServer->FileServerPC = this;
YagFileServer->FileServerWorld = GetWorld();
YagFileServer->Start();
}
void AyagPlayerController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (GEngine)
{
// this condition is never satisfied, even without the IsTimerActive test.
if (YagFileServer->IsValidLowLevel() && Role == ROLE_Authority ) //&& GetWorld()->GetTimerManager().IsTimerActive(YagFileServer->UniqueHandle))
{
float RemainingTime = GetWorld()->GetTimerManager().GetTimerRemaining(YagFileServer->UniqueHandle);
GEngine->AddOnScreenDebugMessage(-1, .1f, FColor::Red, TEXT("remaining time: " + FString::SanitizeFloat(RemainingTime)));
}
}
}
------------------------------------------------------------------------------------------------------
YagServer.cpp:
void UYagFileServer::Start()
{
// ListenerDelegate and UniqueHandle are now class variables
ListenerDelegate = FTimerDelegate::CreateUObject(this, &UYagFileServer::TCPConnectionListener);
FileServerWorld->GetTimerManager().SetTimer(UniqueHandle, ListenerDelegate, 1.f, true);
if (FileServerWorld->GetTimerManager().IsTimerActive(UniqueHandle)) GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Red, FString::Printf(TEXT("UniqueHandle ACTIVE")));
}
void UYagFileServer::TCPConnectionListener()
{
GEngine->AddOnScreenDebugMessage(10, 30.f, FColor::Red, FString::Printf(TEXT("TCPConnectionListener")));
}
Cedric