DLL not loaded in editor

Issue #70 new
Wouter De Keersmaecker created an issue

Hi, thank you for your work on this library!

I’m working on a custom inspector panel in Unity that allows our artist to load some stuff from an FBX file into the Unity Editor. Unfortunately, it seems this library doesn’t work properly at edit-time? Calling ImportFile produces a COMException with the note that the DLL was not loaded. Upon further inspection, it seems that the initialization code in AssimpUnity.cs is only loaded at runtime, but not in the editor.

I fixed this by adding

#if UNITY_EDITOR
    [UnityEditor.InitializeOnLoad]
#endif

to the class, and then adding a static constructor which calls InitializePlugin. This makes sure the DLL loading code is run in the editor too.

Comments (4)

  1. Wouter De Keersmaecker reporter

    During initialization, AssimpUnity also seems to assumes the plugin files are at “app/Plugins/AssimpNet/Native”. However, if this library is part of a package, this path is incorrect in the editor which causes the dll load to fail.

    I fixed this with the following snippet:

    if(!Directory.Exists(editorPluginNativeFolder))
    {
        // Get directory that contains this file.
        string pluginFolder = Path.GetDirectoryName(GetCallerFilePath());
    
        pluginsFolder = Directory.GetParent(pluginFolder).FullName;
        editorPluginNativeFolder = Path.Combine(pluginFolder, "Native");
    }
    

    where GetCallerFilePath is defined as

    private static string GetCallerFilePath([System.Runtime.CompilerServices.CallerFilePath] string filepath = "")
    {
        return filepath;
    }
    

    I can make a PR if you want.

  2. Log in to comment