jacksondunstan / UnityNativeScripting

Unity Scripting in C++
https://jacksondunstan.com/articles/3938
MIT License
1.33k stars 135 forks source link

[Android] Return type within the C# import for the C++ binding function is always void #17

Closed JmgrArt closed 6 years ago

JmgrArt commented 6 years ago

I tried adding another abstract method returning bool in the AbstractBaseBallScript example class and calling the generator (after manually adding a stub override in BaseBallScript to prevent a compilation error in Unity), but the return type of the generated C# binding function is always void. This results in a compilation error when building a player for Android. Building for the Editor is working as expected. The following change seems to fix the issue: (in the file GenerateBindings.cs, at line 8688)

// C# import for the C++ binding function
        AppendCsharpImport(
                GetTypeName(type),
                typeParams,
                funcName,
                invokeParams,
                typeof(void),
                builders.CsharpImports);

Into:


// C# import for the C++ binding function
        AppendCsharpImport(
                GetTypeName(type),
                typeParams,
                funcName,
                invokeParams,
                invokeMethod.ReturnType,
                builders.CsharpImports);
jacksondunstan commented 6 years ago

Hi @JmgrArt, thanks for pointing this out! All the MonoBehaviour "message" functions return void so this seems to have been an oversight that still worked in my testing. I've made your suggested change in commit 2180b3edfea9d58da5242d9c5752b344d9a0b84c. Please let me know if you find any more issues!