- Home /
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
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
Hi @thebebinator, your solution also worked for me! $$anonymous$$any thanks. - $$anonymous$$ax
I got this working using your instructions @thebebinator . Thanks!
By the way: $$anonymous$$ake sure to use a $$anonymous$$athNet.Numerics version compatible with .NET 3.5. In this OneDrive folder you can find 3.20.2 for instance.
@AdamBebko's solution still works mostly (Windows 10, Unity 2019.3.9): 1) created Plugins folder in Assets; 2) downloaded "$$anonymous$$athNet.Numerics-4.9.1.zip" from above link; 3) [solution update] copied $$anonymous$$athNet.Numerics.dll from "netstandard2.0" from zip-file into Plugins folder 4) tested with code from @HackAndSlashDev (see below)
By the way the Unity's Asset Store does not have $$anonymous$$ath.Net at the time of writing.
2021 update: This still seems to be the correct solution with wgarn's modification (use the netstandard2.0 folder instead of the Net35 folder and don't worry about copying over a System.Threading.dll file).
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);
}
}
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:
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.
I've managed to get $$anonymous$$ath.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.
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613102808im_/https://answers.unity.com/themes/thub/images/avi.jpg)