Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

UnityPluginUnload never called

Discussion in 'Editor & General Support' started by Clodo, Jun 29, 2016.

  1. Clodo

    Clodo

    Joined:
    Dec 27, 2013
    Posts:
    40
    Unity 5.4.0b22
    In my tests, UnityPluginUnload it's never called.
    I expect it's called when Unity Editor it's closed, but doesn't occur.
    I expect it's called when Windows Standalone player it's closed, but doesn't occur.

    I'm missing something or i need to open a bug-report? Thanks for any feedback.

    ---------------
    How to reproduce

    My c++ code:

    Code (CSharp):
    1. #include <stdio.h>
    2.  
    3. #include <d3d11.h>
    4. #include <dxgi1_2.h>
    5.  
    6. #include "IUnityInterface.h"
    7. #include "IUnityGraphics.h"
    8. #include "IUnityGraphicsD3D11.h"
    9.  
    10. #pragma comment(lib, "dxgi.lib")
    11.  
    12. namespace
    13. {
    14.     IUnityInterfaces*       g_unity = nullptr;
    15. }
    16.  
    17.  
    18. void logMessage(const char* s)
    19. {
    20.     const char* path = "s:\\unity_plugin_log.txt";
    21.     FILE *f;
    22.     fopen_s(&f, path , "at");
    23.     if (!f) fopen_s(&f, path, "wt");
    24.     fprintf(f, "Log: %s\n", s);
    25.     fclose(f);  
    26. }
    27.  
    28. extern "C"
    29. {
    30.     UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
    31.     {
    32.         g_unity = unityInterfaces;
    33.        
    34.         logMessage("Load");
    35.     }
    36.  
    37.     UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginUnload()
    38.     {
    39.         logMessage("Unload");
    40.     }  
    41.  
    42.     UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API MyTest()
    43.     {
    44.         logMessage("Test");
    45.     }
    46. }
    A C# script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Runtime.InteropServices;
    4.  
    5. public class MyTestScript : MonoBehaviour {
    6.  
    7.     [DllImport("DesktopCapture")]
    8.     private static extern void MyTest();
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.  
    13.         MyTest();
    14.     }
    15.    
    16. }
    Here: https://www.clodo.it/files/varie/UnityPluginUnload.zip
    a zip with both project.

    In my s:\\unity_plugin_log.txt file, i see the "Load" the first time i enter in PlayMode, followed by a "Test".
    But closing Unity Editor doesn't append the "Unload" string.
     
  2. kjohnsen1

    kjohnsen1

    Joined:
    Jan 4, 2015
    Posts:
    3
    I also have found that UnityPluginUnload is not being called on standalone or editor exit. Has their been any progress on this issue? Because of my plugin, Unity quits, but stays running in the background.

    [Edit] - I fixed my issue (bug in my plugin code that was not releasing the plugin objects properly), but still UnityPluginUnload is not being called from what I can gather.
     
    Last edited: Apr 3, 2017
  3. iko79

    iko79

    Joined:
    Jan 21, 2013
    Posts:
    45
    Any update on this? I'm having the same behaviour with 5.6.2f1, I have to free resources but UnityPluginUnload() does not seem to be called anytime.
     
  4. holo-krzysztof

    holo-krzysztof

    Joined:
    Apr 5, 2017
    Posts:
    77
    Sorry to necro-bump, but this is still a thing. Unity version 2017.4.3 ("LTS") exhibits the same behavior.

    I know that Unity Editor actually warns about this when selecting a plugin in the folder hierarchy, but it should get called in a standalone Win32 player nonetheless.
     
  5. BroncoBilli

    BroncoBilli

    Joined:
    Oct 8, 2017
    Posts:
    90
    Bump. I see the same thing even in Unity 2018. Unload not called. What's up w/ that?
     
  6. italiansc

    italiansc

    Joined:
    Sep 14, 2021
    Posts:
    12
    I found the same issue in Unity 2021.1:(