• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by mcough2 · May 23, 2013 at 04:42 PM · dllreferenceslibraries

Unity and MathNET

Hey,

I am having a very noob(ish) problem. I would like to use the MathNet.Numerics Library. When I add the following to my code (only that line to code that works otherwise) and add MathNet.Numerics.dll to my references in MonoDeveloper I can build the file. However when I go to run (push the play button) my unity project I get the following error.

using MathNet.Numerics.IntegralTransforms;

error CS0246: The type or namespace name `MathNet' could not be found. Are you missing a using directive or an assembly reference?

I have the MathNet.Numerics.dll file in the same folder as UnityEngine.dll.

I've tried putting the MathNet.Numerics.dll file into my project folder (Assets) but that give the following error.

TypeLoadException: Could not load type 'MathNet.Numerics.Algorithms.LinearAlgebra.ILinearAlgebraProvider' from assembly 'MathNet.Numerics, Version=2.5.0.27, Culture=neutral, PublicKeyToken=null'.

I don't understand what the problem is. Please Help.

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
9

Answer by AdamBebko · Apr 11, 2016 at 07:33 AM

I got this working.

Steps:

1) Create a folder called Assets/Plugins in your project.

2) go to

https://onedrive.live.com/?id=84F3672F8CDA3E91%21440210&cid=84F3672F8CDA3E91

and download the latest version of MatNet.Numerics.dll in zip format.

3) open the folder called Net35. Unity apparently only runs on this version of .net.

4) copy BOTH MathNet.Numerics.dll AND System.Threading.dll into Assets/Plugins.

Note: Don't touch anything in MonoDevelop. it should reference it automatically.

For me i was installing the newer .net version and I didn't realize it also needed System.Threading.dll. Once I got it in the above format it worked fine.

FYI: I'm on El Capitan OSX11.4 and Unity 5.3.4f1 personal.

Hope that helps! Adam

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image maxdefeber · May 29, 2017 at 07:41 PM 0
Share

Hi @thebebinator, your solution also worked for me! Many thanks. - Max

avatar image SamuelBG13 · Apr 06, 2018 at 01:03 PM 0
Share

I got this working using your instructions @thebebinator . Thanks!

By the way: Make sure to use a MathNet.Numerics version compatible with .NET 3.5. In this OneDrive folder you can find 3.20.2 for instance.

avatar image
3

Answer by HackAndSlashDev · Dec 01, 2015 at 10:40 AM

Well, this answer helped find the answer. I was able to get the Math.NET Numerics 3.9 running on unity on osx El Capitan.

Here are the steps I took:

  • Install NuGet in Monodevelop using this tutorial https://www.youtube.com/watch?v=uHbAgbfgQdU

  • Search for and install Math.NET Numerics using the NuGet plugin. That will also install System.Threading for which you'll have to accept a license agreement.

  • Close monodevelop.

  • NuGet creates a directory called packages under the project folder.
    • I copied "packages/TaskParallelLibrary.1.0.2856.0/lib/Net35" to a folder I named Assets/Libs.

    • Then I also copied the contents of "packages/MathNet.Numerics.3.9.0/lib/net35" to "Assets/Libs/Net35".

    • For correctness sake I placed the readmes and licenses under "Assets/Libs".

    • Finally I deleted the packages directory, and the file Assets/packages.config

That's it. You can test it by dragging the following script onto an object:

 using UnityEngine;
 using System.Collections;
 using Matrix = MathNet.Numerics.LinearAlgebra.Matrix<double>;
 using Vector = MathNet.Numerics.LinearAlgebra.Vector<double>;
 
 
 public class MathTest : MonoBehaviour {
     // *************************************************************************
     void Start() {
         Matrix A = Matrix.Build.DenseOfArray(new double[,] {
             {1,0,0},
             {0,2,0},
             {0,0,3}});
 
         Vector b = Vector.Build.Dense(new double[] {1, 1, 1});
 
         Vector x = A.Solve(b);
         Debug.Log("x = A^-1b: " + x);
     }
 }
 







Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by randomuser · May 23, 2013 at 11:03 PM

You don't add the reference in monodevelop, you add the .dll to your unity project in the editor, which should then add it for use via the "using" statement. Here is the documentation for it:

http://docs.unity3d.com/Documentation/Manual/UsingDLL.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by TriangleKing · May 24, 2013 at 10:10 AM

MathNet requires .NET 4, which unity's version of monodevelop doesn't support.

If you manage to get it working, please tell me! I've been trying to use Iridium's stable distribution, but it's giving me bogus numbers. Iridium was discontinued in 2008 so I'm thinking it has lots of bugs. And I really don't want to implement my own probability distributions.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image phaserescu · Sep 26, 2016 at 08:44 AM 1
Share

I've managed to get Math.Net working in a Unity3d project and because the steps weren't super clear, I've also created a sample GitHub repo with a working test.

https://github.com/phaser/UnityMathNet

avatar image
0

Answer by TheD0ctor · Dec 14, 2016 at 06:52 AM

You could use Math.NET for Unity https://www.assetstore.unity3d.com/en/#!/content/77081 https://www.assetstore.unity3d.com/en/#!/content/77082

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to reference an enum from outside a built DLL 1 Answer

Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers

InControl does not work as a managed DLL. 0 Answers

Importing a DLL that contains C#-wrapped C++ Code 0 Answers

System.EntryPointNotFoundException: CreateNLSocket 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges