Download

Delayed messages not working in either IMessageBus->Send(), FMessageEndpoint approach.

I have 2 actors that can talk to each other. Each has an FMessageEndpoint instance and currently they fire messages back and forth between each other using the Default Message Bus in Unreal.

So far so good.

The IMessageBus->Send() (implemented in FMessageEndpoint as well) takes a “Delay” argument. An FTimespan value, which can be configured FTimespan::FromSeconds(…), etc.

However, it doesn’t matter what value I use for the Delay… the message always arrives to the other actor’s handle method INSTANTLY. :frowning:

I have tried FTimespan::FromSeconds(), even FTimespan::FromHours(). Also just the default FTimespan(D,H,S) constructor. All result in instantly-arriving messages.

It seems hardly anyone is using this module (hence my inability to find much written about it), but I’m wondering if a bug has crept into the code over time and the Delay is not working as expected?



// Creating the FMessageEndpoint and setting up Handler Delegate
messaging = FMessageEndpoint::Builder(TEXT("EndPoint")).Handling<FTestMessage>(this, &AMessageSendActor::HandleMessage);

// Sending a Message
if (target != nullptr) {            
   if (messaging->IsEnabled()) {
      if (messaging->IsConnected()) {
         messaging->Send(new FTestMessage("HOWDY!!!", this), target->messaging->GetAddress(), FTimespan(0, 0, 20)); // 20s delay
      }
   }
}

// Handling the message

void AMessageSendActor::HandleMessage(const FTestMessage& Message, const TSharedRef<IMessageContext, ESPMode::ThreadSafe>& Context)
{

    UE_LOG(LogTemp, Warning, TEXT("%s, from: %s"), *Message.val, *Message.sender->GetName());
}




So… I downloaded the source code and in Messaging/MessageRouter.cpp



    if (false) //(Context->GetTimeSent() > CurrentTime)
    {
        DelayedMessages.HeapPush(FDelayedMessage(Context, ++DelayedMessagesSequence));
    }
    else
    {
        DispatchMessage(Context);
    }


if (false) // …

So… it’s not even doing the delayed messages. Hmm… not sure why the developers have commented this out.

I’m currently recompiling the UE source with this added back in to test whether it was taken out for any good reason.

If not, will submit a bug report and a small test project for the UE devs.

UPDATE - New Pull Request:
https://github.com/EpicGames/UnrealEngine/pull/4574