i was trying to use the “assimp.net” library in unity (via C#-Script). I compiled the C#-Version of the library with “.Net v3.5” as target.
However, i still have trouble calling library functions. For those who do not know assimp: it’s a C++ library for loading 3D models (at runtime). There’s also a C#-Wrapper library (called assimp.net).
I’m getting following exception:
Marshal.GetHRForLastWin32Error isn’t implemented in Mono at all (my guess being that it’s specific to Windows so they decided to simply throw a not implemented exception). The real reason you’re getting that is because the assembly can’t be loaded and it’s attempting to get more information as to why. Are you using Pro?
Hey, thanks for the answer. I’m using the 30-days trial, so yeah that should be pro.
Actually the only thing i’ve done is checking out http://assimp-net.googlecode.com/svn/trunk and compiling the project (after changing target framework to “.net 3.5”). Then i imported the resulting “dll” into the “Plugins”-subfolder of the unity3d-project’s assets-folder. Then i created a new C#-behaviour script with very simple code to test if the library is accessible from there.
Well, assimp-net is just a C#-wrapper for the C+±project, so do i need to take care of something else i missed? Any ideas would be very appriciated. I’m quite sure some guys already managed to use assimp in unity (because that’s how i got the idea from google) but somehow i got stuck at this point.
I got to the point you did before remembering that you need Pro for native plugins. I bypassed the issue you have by just commenting out the calls to that method which just result in less-useful error messages being displayed when the assembly fails to load. So if you get anywhere, I’d be curious to know what you come up with.
btw. i’m using another library (for zipping/unzipping files) so that should not be the problem.
Best thing i can offer is another part of the code where i call library functions, i guess:
using UnityEngine;
using System.Collections;
using Assimp;
using Assimp.Configs;
public class NewBehaviourScript : MonoBehaviour
{
// Use this for initialization
void Start ()
{
string fileName = "C:/Users/Timm/Downloads/Monster_1/em1000.obj";
//Create a new importer
AssimpImporter importer = new AssimpImporter(); // THIS SEEMS TO WORK
Scene model = importer.ImportFile(fileName); // THIS THROWS THE EXCEPTION
importer.Dispose();
}
// Update is called once per frame
void Update () {
}
}
P.s: okey, had a look into the C# code which is throwing an exception. So you’re right, it fails to load the “Assimp32.dll” (the actual C++ lib). Now i installed the complete assimp-sdk, but still doesn’t find the dll. That’s probably not too amazing because i really have no clue where to put it …
Interesting - this goes along with what someone posted a week or so ago with native code DLLs loading ok from the root directory - which isn’t mentioned in the documentation.
Hey, another question concering a similar problem.
I want to run the same C# script on Android now, and the adb-logcat output says “unable to find Assimp32.dll”. Any idea, where to put the dll to deploy it on the android device?
One problem is that the assimpnet.dll looks for the assimpPLATFORM.dll (i.e. assimp64.dll) in your PATH/TO/PROJECT/ProjectName folder. The assimpnet.dll is not written to look for the dlls dynamically and expects them to be in the executable directory (Directory.GetCurrentDirectory Method (System.IO) | Microsoft Learn)
If you copy them in there it should work.
Sorry for necroing this thread but mayhaps someone still needs this little piece of advice.
Hey guys, I’m also attempting to get assimp up and running using the assimp-net library. However, after fixing the problem addressed in this thread, I’m receiving the following error:
NullReferenceException: Object reference not set to an instance of an object
(wrapper stelemref) object:stelemref (object,intptr,object)
System.String.Format (System.String format, System.Object arg0, System.Object arg1, System.Object arg2) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/String.cs:1863)
Assimp.Material.CreateFullyQualifiedName (System.String baseName, TextureType texType, Int32 texIndex)
Assimp.MaterialProperty.get_FullyQualifiedName ()
Assimp.Material.AddProperty (Assimp.MaterialProperty matProp)
Assimp.Material.Assimp.IMarshalable<Assimp.Material,Assimp.Unmanaged.AiMaterial>.FromNative (Assimp.Unmanaged.AiMaterial& nativeValue)
Assimp.MemoryHelper.FromNativeArray[Material,AiMaterial] (IntPtr nativeArray, Int32 length, Boolean arrayOfPointers)
Assimp.Scene.Assimp.IMarshalable<Assimp.Scene,Assimp.Unmanaged.AiScene>.FromNative (Assimp.Unmanaged.AiScene& nativeValue)
Assimp.MemoryHelper.FromNativePointer[Scene,AiScene] (IntPtr ptr)
Assimp.Scene.FromUnmanagedScene (IntPtr scenePtr)
Assimp.AssimpContext.ImportFile (System.String file, PostProcessSteps postProcessFlags)
Assimp.AssimpContext.ImportFile (System.String file)
assImporter.Start () (at Assets/assImporter.cs:13)
Hi there
I’m trying to use assimp.NET in unity but i cannot get a good meshes from ifc file…I think it’s a probleme from the tree structure…
someone succeed that before?
NullReferenceException: Object reference not set to an instance of an object
(wrapper stelemref) object:stelemref (object,intptr,object)
As far as I can tell it is because a pointer reference is being garbage collected while it is in an unmanaged DLL (assimp64.dll).
I hooked the UnityEngine.dll into AssimpNet so that I could spit out a gratuitous amount of debug messages and found that by doing so the references that were going null were somehow magically kept alive.
You will have to call GC.KeepAlive() to keep your IntPtrs alive long enough for them to be processed through the variety of unmanaged memory calls (looks to be largely in MemoryHelper.cs) while the file is being imported.
If you look at the stack trace you can see where the pointer is being lost in the midst of importing materials.
I haven’t got it exactly where I want it yet, but I am able to use AssimpNet 3.3 in Unity 5.5.4f to import models at runtime.
I am stuck with the same NullReferenceException: Object reference not set to an instance of an object
(wrapper stelemref) object:stelemref (object,intptr,object).
Can you please explain in detail what exactly I need to do resolve this issue?
In which function I have to call GC.KeepAlive in MemoryHelper.cs?
It could be great if you can post the modified MemoryHelper.cs.
I’m actually back to the drawing board on this one. GC.KeepAlive did not in fact do what I wanted it to do. The Debug messages I put in previously were somehow allowing it to work (which I assumed just meant it was keeping the references alive) but it is not working properly. I will be investigating it further in the next few weeks though. I will post again to let you know what I find.