How to solve the problem of using BroadCast() of Delegate in C++/WinRT Async function??

Hi all
I am currently creating Voice Recognition by using C++/WinRT and binding it into Unreal Engine. Because I wanna let my blueprint widget to show the words when it got recognized, I created a DECLARE_MULTICAST_DELEGATE in my C++/WinRT file and use a function to BroadCast() it when words are recognized. Here is the code

VoiceRecog.h
for problem

VoiceReocg.cpp


BP_WinRTVoiceRec(Create from VoiceReocg.cpp)

The problem is when it got recognized it crashed, and I checked the log it said

It seems like it did enter the function and broadcast, but stuck at the bind event…
I’ve testted this logic by trigger the ActivateDIspatcher() function with normal blueprint Actor, it works fine…so I believe it definitely should be the problem of this Async function.

Does anyone know how to solve this?
Thank you!

This topic has been moved from International to Programming & Scripting: Blueprint.

When posting, please review the categories to ensure your topic is posted in the most relevant space.

Hopefully, this category change will help in getting an answer. In the meantime, good luck and happy developing! :slight_smile:

The WinRT callback is executing in a different thread, and blueprint event can only run on main thread, or something like that.
Activate dispatcher on the game thread instead :

#include "Async.h"

AsyncTask(ENamedThreads::GameThread, [this]() {
    ActivateDispatcher();
});
1 Like

Hi!!Thanks for helping!!

Although you said use
#include “Async.h”

I found that I have to use this
#include “Async/Async.h”

And the problem is solved, it works!!!
Thank you!!! I’ve struggled for this problem for 2 weeks, you are my hero!!!
:grinning: