Hi there,
delegates cause heavy headaches to me. I have the following setup in my project:
WoEPhotonListener.h
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnOperationResponse, FPhotonOperationResponse, FPOperationResponse);
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnEvent, FPhotonEventData, FPEventData);
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnStatusChanged, int32, FPStatus);
DECLARE_DYNAMIC_DELEGATE_TwoParams(FOnDebugReturn, int32, FPDebugLevel, FString, FPDebugMessage);
class WORLDOFELEMENTS_API WoEPhotonListener : public PhotonListener
{ .....
FOnOperationResponse ForwardPhotonOperationResponse;
FOnEvent ForwardPhotonEvent;
FOnStatusChanged ForwardPhotonStatusChanged;
FOnDebugReturn ForwardPhotonDebugReturn;
WoEPhotonListener.cpp (Example method)
void WoEPhotonListener::onStatusChanged(int statusCode)
{
UE_LOG(WoEGeneral, Warning, TEXT("Listener onStatusChanged was called."));
if (ForwardPhotonStatusChanged.ExecuteIfBound(statusCode))
{
UE_LOG(WoEGeneral, Warning, TEXT("ForwardPhotonStatusChanged executed."));
}
else
{
UE_LOG(WoEGeneral, Error, TEXT("ForwardPhotonStatusChanged not executed."));
}
}
In my WoEPlayerController.cpp I have this in place:
void AWoEPlayerController::PostInitializeComponents()
{
UE_LOG(WoEGeneral, Warning, TEXT("AWoEPlayerController::PostInitializeComponents called."));
UWorld* World = GetWorld();
GI = Cast<UWoEGameInstance>(World->GetGameInstance());
PListener = GI->PhotonEngine->GetPhotonListener();
PListener.ForwardPhotonOperationResponse.BindDynamic(this, &AWoEPlayerController::HandleOnOperationResponse);
PListener.ForwardPhotonEvent.BindDynamic(this, &AWoEPlayerController::HandleOnEvent);
PListener.ForwardPhotonStatusChanged.BindDynamic(this, &AWoEPlayerController::HandleOnStatusChanged);
PListener.ForwardPhotonDebugReturn.BindDynamic(this, &AWoEPlayerController::HandleOnDebugReturn);
if (PListener.ForwardPhotonStatusChanged.IsBound())
{
UE_LOG(WoEGeneral, Warning, TEXT("ForwardPhotonStatusChanged bound!"));
}
FTimerHandle TimerHandle;
GetWorldTimerManager().SetTimer(TimerHandle, this, &AWoEPlayerController::CallService, 1.0f, true);
Super::PostInitializeComponents();
}
Everything compiles without errors or warnings. Pressing play in the editor gives the following log:
[0063.11][310]LogPlayLevel: PIE: Created PIE world by copying editor world from /Temp/Untitled_1.Untitled_1 to /Temp/UEDPIE_0_Untitled_1.Untitled_1 (0.005255s)
[0063.13][310]WoEGeneral:Warning: WoEPhotonEngine Constructor called.
[0063.13][310]WoEGeneral:Warning: WoEPhotonListner Constructor called.
[0063.13][310]WoEGeneral:Warning: WoEPhotonListner created.
[0063.13][310]WoEGeneral:Warning: PhotonPeer created.
[0063.13][310]LogInit: XAudio2 using 'Speaker/HP (Realtek High Definition Audio)' : 2 channels at 48 kHz using 32 bits per sample (channel mask 0x3)
[0063.14][310]LogInit: FAudioDevice initialized.
[0063.19][310]LogWorld: Game class is 'WoELoginGameMode'
[0063.19][310]LogWorld: Bringing World /Temp/UEDPIE_0_Untitled_1.Untitled_1 up for play (max tick rate 60) at 2015.09.18-12.48.33
[0063.19][310]LogActor:Warning: GameSession /Temp/UEDPIE_0_Untitled_1.Untitled_1:PersistentLevel.GameSession_0 has natively added scene component(s), but none of them were set as the actor's RootComponent - picking one arbitrarily
[0063.19][310]LogActor:Warning: GameNetworkManager /Temp/UEDPIE_0_Untitled_1.Untitled_1:PersistentLevel.GameNetworkManager_0 has natively added scene component(s), but none of them were set as the actor's RootComponent - picking one arbitrarily
[0063.19][310]LogWorld: Bringing up level for play took: 0.001802
[0063.19][310]WoEGeneral:Warning: WoEPhotonListner Constructor called.
[0063.19][310]WoEGeneral:Warning: AWoEPlayerController::PostInitializeComponents called.
[0063.19][310]WoEGeneral:Warning: ForwardPhotonStatusChanged bound!
[0063.19][310]PIE: Info Play in editor start time for /Temp/UEDPIE_0_Untitled_1 0.377
[0075.02][782]WoEGeneral:Warning: Listener onStatusChanged was called.
[0075.02][782]WoEGeneral:Error: ForwardPhotonStatusChanged not executed.
[0075.03][782]WoEGeneral:Warning: Listener onStatusChanged was called.
[0075.03][782]WoEGeneral:Error: ForwardPhotonStatusChanged not executed.
What am I missing? Why does it bind in WoEPlayerController but in the declaring listener it states “not bound”? When I use Execute() instead of ExecuteIfBound() I get the following error:
[2015.09.18-10.41.05:521][900]WoEGeneral:Warning: Listener onStatusChanged was called.
[2015.09.18-10.41.05:539][900]LogWindows:Error: Windows GetLastError: Der Vorgang wurde erfolgreich beendet. (0)
[2015.09.18-10.41.12:245][900]LogCrashTracker:
[2015.09.18-10.41.12:307][900]LogCrashTracker:
[2015.09.18-10.41.12:307][900]LogWindows: === Critical error: ===
Assertion failed: Object.IsValid() != false [File:C:\Temp\Epic Games\4.9\Engine\Source\Runtime\Core\Public\UObject\ScriptDelegates.h] [Line: 220]
ProcessDelegate() called with no object bound to delegate!
[2015.09.18-10.41.12:439][900]LogExit: Executing StaticShutdownAfterError