- Hi, I have a Json data string which I have to process which comes from making a HTTP request.
- I’ve created a
FRunnable
thread class to handle the processing of this data.
- I’ve added a
DECLARE_DELEGATE(FJsonRead);
in the thread class.
JsonRead
in the thread class. On no. 101 in cpp file section I wrote
void FCoalaReadJsonAsync::JsonToCoalaArea(FString JsonRaw, int defaultBuildingLevel, bool clampToDefaultBuildingLevel, int limitMaxBuildingLevelTo, UCoalaArea* _result)
{
FCoalaReadJsonAsync::JsonToCoalaArea(*JsonRaw, defaultBuildingLevel, clampToDefaultBuildingLevel, limitMaxBuildingLevelTo, true, _result);
isDone = true;
JsonRead.Execute();
}
- I’ve binded a UFUNCTION in my Mapbase class with the function
void ASWPMapBase::PrintJsonString()
{
UE_LOG(LogFlying, Warning, TEXT("Json Reading is done "));
}
My question is :
Can I add a delegate in the Thread class to get to know when its processing is done ? I tried the same by calling the on the mentioned line number above.
Here is how I’m calling the thread function:
void ASWPMapBase::PrintTheString(FString str)
{
UE_LOG(LogFlying, Warning, TEXT("Printing SUCCESS: "));
UCoalaArea* ret = NewObject<UCoalaArea>();
ret->AddToRoot();
FCoalaReadJsonAsync* RunnableThread = FCoalaReadJsonAsync::JoyInit(str, 3, true, 0, ret);
RunnableThread->JsonRead.BindUFunction(this, "PrintJsonString");
}
And here is the response log I’m getting:
LogFlying: Warning: Printing SUCCESS:
LogFlying: Warning: Json Reading is done
LogFlying: Warning: Printing SUCCESS:
LogFlying: Warning: Printing SUCCESS:
LogFlying: Warning: Printing SUCCESS:
LogFlying: Warning: Printing SUCCESS:
LogFlying: Warning: Printing SUCCESS:
LogFlying: Warning: Printing SUCCESS:
LogFlying: Warning: Printing SUCCESS:
LogFlying: Warning: Printing SUCCESS:
**AS YOU SEE THE THREAD IS CALLING JSON READ DONE ONLY ONCE BUT I CALLED THE THREAD SO MANY TIMES!
HOW CAN I GET THE FUNCTION CALL BACK FROM THREAD IN ANOTHER ACTOR CLASS ?**