- Home /
Problems with using openhardwaremonitorlib.dll with Unity.
Hello everyone! So, I am trying to work the OpenHardwareMonitorLib.dll with Unity to get some hardware stats displayed within Unity. I have added the plugin and it seems to be placed okay. I am getting some NullReferenceExceptions when I hit Play. Its because of the library for sure but I couldn't figure out exactly how to fix that. Could anyone please share their experiences with it? Any help would be really appreciated!
The code I am using is as follows:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using OpenHardwareMonitor;
using OpenHardwareMonitor.Hardware;
using OpenHardwareMonitor.Collections;
public class MenuManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GetSystemInfo();
}
// Update is called once per frame
void Update()
{
}
public class UpdateVisitor : IVisitor
{
public void VisitComputer(IComputer computer)
{
computer.Traverse(this);
}
public void VisitHardware(IHardware hardware)
{
hardware.Update();
foreach (IHardware subHardware in hardware.SubHardware) subHardware.Accept(this);
}
public void VisitSensor(ISensor sensor) { }
public void VisitParameter(IParameter parameter) { }
}
public static void GetSystemInfo()
{
UpdateVisitor updateVisitor = new UpdateVisitor();
Computer computer = new Computer();
computer.Open();
computer.CPUEnabled = true;
computer.Accept(updateVisitor);
for (int i = 0; i < computer.Hardware.Length; i++)
{
if (computer.Hardware[i].HardwareType == HardwareType.CPU)
{
for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
{
if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
Console.WriteLine(computer.Hardware[i].Sensors[j].Name + ":" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
}
}
}
computer.Close();
}
}
Answer by hamzzashaffi · May 06 at 03:42 PM
@chinapdyh Ah right! Nice workaround! Any idea if the direct route is even possible to do with Unity?
Your answer
![](https://koobas.hobune.stream/wayback/20220613030208im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
reduce size of included dlls? 2 Answers
Why is UnityEngine.dll not signed? 0 Answers
how to load Dll into Unity 2 Answers
Using dll's from C#? 4 Answers