Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

bidirectional link between java application and an unreal game


I am thinking about making a bidirectional link between a java application which controls some parts of an unreal game. Setting and getting game values. Probably a dll can make it. I know how to use a dll in an unreal game and in a java application.

I don't know how to call a game method by the java application. E.g. I want to read the window size of the game or set the player's position. Would be callbacks, provided by the dll to the game, a solution?


Product Version: UE 4.16
more ▼

asked Aug 09 '17 at 08:41 PM in C++ Programming

avatar image

63 4 8 13

avatar image Zarionae Apr 14 '18 at 09:59 PM

Did you managed to do it and could you explain to me how? :O I'm looking for a similar fix

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

In case someone else needs this here is how it's done. This link between c++ and java made possible with jni. The easiest way to access java is to modify game activity class with upl using a tag . For example:

       public void testFunction()
       Log.debug("caled java code");

Then in c++ function you call:

 static jmethodID javaMethodId;
     JNIEnv* env = FAndroidApplication::GetJavaEnv();
     javaMethodId = FJavaWrapper::FindMethod(env, 
         FJavaWrapper::GameActivityClassID, "testFunction", "()V", false);
     FJavaWrapper::CallVoidMethod(env, FJavaWrapper::GameActivityThis, javaMethodId);

You need to know the sinature of java function, you can find it here. This is a common knowledge that could be found, I just summarised it. What I couldn't find is how to call back from java to c++ and here is how you do it. Again using simply game activity you add function declaration of c++ method in java as described previously:

       private static native void howToGetString(String code);

In c++(I used the same file from where I call java class) you do the following:

 #include <jni.h>
 static FCriticalSection ReceiversLock;
 static FString OurString = "";
 extern "C"
     JNIEXPORT void Java_com_epicgames_ue4_GameActivity_howToGetString(JNIEnv * jni, jclass clazz, jstring code)
         const char* charsId = jni->GetStringUTFChars(code, 0);
         OurString = FString(UTF8_TO_TCHAR(charsId));
         jni->ReleaseStringUTFChars(code, charsId);

Now you can call function howToGetString("a string ") and it will call you c++ class. I used it in OnActivityResult to get data from my intent. Hope this will help someone.

more ▼

answered May 31 '18 at 02:13 PM

avatar image

241 2 6 15

avatar image uerceg Oct 01 '18 at 04:09 PM

Lovely. Works just like described. Thanks!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Short answer; using a dll does not work! Each process runs its own copy of the dll in his process space. Sharing dll data is not possible. Inter process communication do this.

more ▼

answered Aug 28 '17 at 09:02 AM

avatar image

63 4 8 13

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question