My game is created using Blueprints but I had to create a BlueprintFunctionLibrary for the part of the logic that handles player information with the server (like username, password…). Inside the function I’m using JNI as I already have a really good server that handles different function as well as relation with the DB. When I’m running the game from UE it is running fine (did 700+ function call tests, every time it worked as it should), but the problem is that as soon as I create a shipping form of the game, it stop working. From what I understand from other thread, a possible problem is that the part that fails should run on the game thread. So I want to at least give this suggestion a try and run it there.
What do I have to use inside the function so that the code runs on game thread? And how do I tell it to wait for that code to finish to avoid other problems that may appear if this code runs later then some other stuff that depend on it.
This will also help me in the future to learn how to use it, in case there are situation in which running code in game thread is the only way to do it.
Simple BlueprintFunctionLibrary .h file content
UCLASS()
class MOREFUNTOGETHER_API UTestSocket : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable, Category = "MyCategory")
static int testFunction();
};
.cpp
int UTest::testFunction() {
// Code that should run on game thread, which return a number as a test, and the rest of the execution waits until "testFunction" finishes
}
Just as a note for anyone who wanders what is it that I’m using, I’m using JNI inside the testFunction that has the Socket with the server, and the problem is when I’m calling the function FindClass, it returns nullptr in shipping form, and not while running from editor. And on some threads not related to UE they were saying that a problem might be that the function isn’t running on the main thread, which from what I understand that is game thread in UE.